auth
2014-07-18
Child:7b9e0fc20256
auth/config.go
Start rewriting the repo. This code originally was a carbon copy of https://github.com/RangelReale/osin, but I am methodically stripping out the extensible nature of it for a simpler interface, while simultaneously bringing the style into line with the Ducky style.
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/config.go Fri Jul 18 07:13:22 2014 -0400 1.3 @@ -0,0 +1,70 @@ 1.4 +package oauth2 1.5 + 1.6 +// AllowedAuthorizeType is a collection of allowed auth request types 1.7 +type AllowedAuthorizeType []AuthorizeRequestType 1.8 + 1.9 +// Exists returns true if the auth type exists in the list 1.10 +func (t AllowedAuthorizeType) Exists(rt AuthorizeRequestType) bool { 1.11 + for _, k := range t { 1.12 + if k == rt { 1.13 + return true 1.14 + } 1.15 + } 1.16 + return false 1.17 +} 1.18 + 1.19 +// AllowedAccessType is a collection of allowed access request types 1.20 +type AllowedAccessType []GrantType 1.21 + 1.22 +// Exists returns true if the access type exists in the list 1.23 +func (t AllowedAccessType) Exists(rt GrantType) bool { 1.24 + for _, k := range t { 1.25 + if k == rt { 1.26 + return true 1.27 + } 1.28 + } 1.29 + return false 1.30 +} 1.31 + 1.32 +// ServerConfig contains server configuration information 1.33 +type ServerConfig struct { 1.34 + // Authorization token expiration in seconds (default 5 minutes) 1.35 + AuthorizationExpiration int32 1.36 + 1.37 + // Access token expiration in seconds (default 1 hour) 1.38 + AccessExpiration int32 1.39 + 1.40 + // Token type to return 1.41 + TokenType string 1.42 + 1.43 + // List of allowed authorize types (only CodeAuthRT by default) 1.44 + AllowedAuthorizeTypes AllowedAuthorizeType 1.45 + 1.46 + // List of allowed access types (only AUTHORIZATION_CodeAuthRT by default) 1.47 + AllowedAccessTypes AllowedAccessType 1.48 + 1.49 + // HTTP status code to return for errors - default 200 1.50 + // Only used if response was created from server 1.51 + ErrorStatusCode int 1.52 + 1.53 + // If true allows client secret also in params, else only in 1.54 + // Authorization header - default false 1.55 + AllowClientSecretInParams bool 1.56 + 1.57 + // If true allows access request using GET, else only POST - default false 1.58 + AllowGetAccessRequest bool 1.59 +} 1.60 + 1.61 +// NewServerConfig returns a new ServerConfig with default configuration 1.62 +func NewServerConfig() ServerConfig { 1.63 + return ServerConfig{ 1.64 + AuthorizationExpiration: 250, 1.65 + AccessExpiration: 3600, 1.66 + TokenType: "bearer", 1.67 + AllowedAuthorizeTypes: AllowedAuthorizeType{CodeAuthRT}, 1.68 + AllowedAccessTypes: AllowedAccessType{AuthorizationCodeGrant}, 1.69 + ErrorStatusCode: 200, 1.70 + AllowClientSecretInParams: false, 1.71 + AllowGetAccessRequest: false, 1.72 + } 1.73 +}