...

Source file src/github.com/ory/fosite/fosite.go

Documentation: github.com/ory/fosite

     1  /*
     2   * Copyright © 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   *
    16   * @author		Aeneas Rekkas <aeneas+oss@aeneas.io>
    17   * @copyright 	2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
    18   * @license 	Apache-2.0
    19   *
    20   */
    21  
    22  package fosite
    23  
    24  import (
    25  	"html/template"
    26  	"net/http"
    27  	"reflect"
    28  
    29  	"github.com/ory/fosite/i18n"
    30  )
    31  
    32  // AuthorizeEndpointHandlers is a list of AuthorizeEndpointHandler
    33  type AuthorizeEndpointHandlers []AuthorizeEndpointHandler
    34  
    35  // Append adds an AuthorizeEndpointHandler to this list. Ignores duplicates based on reflect.TypeOf.
    36  func (a *AuthorizeEndpointHandlers) Append(h AuthorizeEndpointHandler) {
    37  	for _, this := range *a {
    38  		if reflect.TypeOf(this) == reflect.TypeOf(h) {
    39  			return
    40  		}
    41  	}
    42  
    43  	*a = append(*a, h)
    44  }
    45  
    46  // TokenEndpointHandlers is a list of TokenEndpointHandler
    47  type TokenEndpointHandlers []TokenEndpointHandler
    48  
    49  // Append adds an TokenEndpointHandler to this list. Ignores duplicates based on reflect.TypeOf.
    50  func (t *TokenEndpointHandlers) Append(h TokenEndpointHandler) {
    51  	for _, this := range *t {
    52  		if reflect.TypeOf(this) == reflect.TypeOf(h) {
    53  			return
    54  		}
    55  	}
    56  
    57  	*t = append(*t, h)
    58  }
    59  
    60  // TokenIntrospectionHandlers is a list of TokenValidator
    61  type TokenIntrospectionHandlers []TokenIntrospector
    62  
    63  // Append adds an AccessTokenValidator to this list. Ignores duplicates based on reflect.TypeOf.
    64  func (t *TokenIntrospectionHandlers) Append(h TokenIntrospector) {
    65  	for _, this := range *t {
    66  		if reflect.TypeOf(this) == reflect.TypeOf(h) {
    67  			return
    68  		}
    69  	}
    70  
    71  	*t = append(*t, h)
    72  }
    73  
    74  // RevocationHandlers is a list of RevocationHandler
    75  type RevocationHandlers []RevocationHandler
    76  
    77  // Append adds an RevocationHandler to this list. Ignores duplicates based on reflect.TypeOf.
    78  func (t *RevocationHandlers) Append(h RevocationHandler) {
    79  	for _, this := range *t {
    80  		if reflect.TypeOf(this) == reflect.TypeOf(h) {
    81  			return
    82  		}
    83  	}
    84  
    85  	*t = append(*t, h)
    86  }
    87  
    88  // Fosite implements OAuth2Provider.
    89  type Fosite struct {
    90  	Store                      Storage
    91  	AuthorizeEndpointHandlers  AuthorizeEndpointHandlers
    92  	TokenEndpointHandlers      TokenEndpointHandlers
    93  	TokenIntrospectionHandlers TokenIntrospectionHandlers
    94  	RevocationHandlers         RevocationHandlers
    95  	Hasher                     Hasher
    96  	ScopeStrategy              ScopeStrategy
    97  	AudienceMatchingStrategy   AudienceMatchingStrategy
    98  	JWKSFetcherStrategy        JWKSFetcherStrategy
    99  	HTTPClient                 *http.Client
   100  	UseLegacyErrorFormat       bool
   101  
   102  	// TokenURL is the the URL of the Authorization Server's Token Endpoint.
   103  	TokenURL string
   104  
   105  	// SendDebugMessagesToClients if set to true, includes error debug messages in response payloads. Be aware that sensitive
   106  	// data may be exposed, depending on your implementation of Fosite. Such sensitive data might include database error
   107  	// codes or other information. Proceed with caution!
   108  	SendDebugMessagesToClients bool
   109  
   110  	// MinParameterEntropy controls the minimum size of state and nonce parameters. Defaults to fosite.MinParameterEntropy.
   111  	MinParameterEntropy int
   112  
   113  	// FormPostHTMLTemplate sets html template for rendering the authorization response when the request has response_mode=form_post. Defaults to fosite.FormPostDefaultTemplate
   114  	FormPostHTMLTemplate *template.Template
   115  
   116  	// ClientAuthenticationStrategy provides an extension point to plug a strategy to authenticate clients
   117  	ClientAuthenticationStrategy ClientAuthenticationStrategy
   118  
   119  	ResponseModeHandlerExtension ResponseModeHandler
   120  
   121  	// MessageCatalog is the catalog of messages used for i18n
   122  	MessageCatalog i18n.MessageCatalog
   123  }
   124  
   125  const MinParameterEntropy = 8
   126  
   127  // GetMinParameterEntropy returns MinParameterEntropy if set. Defaults to fosite.MinParameterEntropy.
   128  func (f *Fosite) GetMinParameterEntropy() int {
   129  	if f.MinParameterEntropy == 0 {
   130  		return MinParameterEntropy
   131  	} else {
   132  		return f.MinParameterEntropy
   133  	}
   134  }
   135  
   136  var defaultResponseModeHandler = &DefaultResponseModeHandler{}
   137  
   138  func (f *Fosite) ResponseModeHandler() ResponseModeHandler {
   139  	if f.ResponseModeHandlerExtension == nil {
   140  		return defaultResponseModeHandler
   141  	}
   142  	return f.ResponseModeHandlerExtension
   143  }
   144  

View as plain text