auth
2014-09-01
Parent:1aa3a85ff853
auth/config.go.old
Rough out tokens and begin the memstore. Rough out the Token type for working with OAuth2 access and refresh tokens. Rough out the TokenStore interface that dictates how Tokens will be stored and retrieved. Write tests for the successful (in the working-as-intended sense) calls to TokenStore. Begin a Memstore type that stores data in memory. Implement the TokenStore interface for Memstore.
| paddy@23 | 1 package auth |
| paddy@23 | 2 |
| paddy@23 | 3 import "time" |
| paddy@23 | 4 |
| paddy@23 | 5 // AllowedAuthorizeType is a collection of allowed auth request types |
| paddy@23 | 6 type AllowedAuthorizeType []AuthorizeRequestType |
| paddy@23 | 7 |
| paddy@23 | 8 // Exists returns true if the auth type exists in the list |
| paddy@23 | 9 func (t AllowedAuthorizeType) Exists(rt AuthorizeRequestType) bool { |
| paddy@23 | 10 for _, k := range t { |
| paddy@23 | 11 if k == rt { |
| paddy@23 | 12 return true |
| paddy@23 | 13 } |
| paddy@23 | 14 } |
| paddy@23 | 15 return false |
| paddy@23 | 16 } |
| paddy@23 | 17 |
| paddy@23 | 18 // AllowedAccessType is a collection of allowed access request types |
| paddy@23 | 19 type AllowedAccessType []GrantType |
| paddy@23 | 20 |
| paddy@23 | 21 // Exists returns true if the access type exists in the list |
| paddy@23 | 22 func (t AllowedAccessType) Exists(rt GrantType) bool { |
| paddy@23 | 23 for _, k := range t { |
| paddy@23 | 24 if k == rt { |
| paddy@23 | 25 return true |
| paddy@23 | 26 } |
| paddy@23 | 27 } |
| paddy@23 | 28 return false |
| paddy@23 | 29 } |
| paddy@23 | 30 |
| paddy@23 | 31 // ServerConfig contains server configuration information |
| paddy@23 | 32 type ServerConfig struct { |
| paddy@23 | 33 // Authorization token expiration in seconds (default 5 minutes) |
| paddy@23 | 34 AuthorizationExpiration int32 |
| paddy@23 | 35 |
| paddy@23 | 36 // Access token expiration in seconds (default 1 hour) |
| paddy@23 | 37 AccessExpiration int32 |
| paddy@23 | 38 |
| paddy@23 | 39 // Token type to return |
| paddy@23 | 40 TokenType string |
| paddy@23 | 41 |
| paddy@23 | 42 // List of allowed authorize types (only CodeAuthRT by default) |
| paddy@23 | 43 AllowedAuthorizeTypes AllowedAuthorizeType |
| paddy@23 | 44 |
| paddy@23 | 45 // List of allowed access types (only AUTHORIZATION_CodeAuthRT by default) |
| paddy@23 | 46 AllowedAccessTypes AllowedAccessType |
| paddy@23 | 47 |
| paddy@23 | 48 // HTTP status code to return for errors - default 200 |
| paddy@23 | 49 // Only used if response was created from server |
| paddy@23 | 50 ErrorStatusCode int |
| paddy@23 | 51 |
| paddy@23 | 52 // If true allows client secret also in params, else only in |
| paddy@23 | 53 // Authorization header - default false |
| paddy@23 | 54 AllowClientSecretInParams bool |
| paddy@23 | 55 |
| paddy@23 | 56 // If true allows access request using GET, else only POST - default false |
| paddy@23 | 57 AllowGetAccessRequest bool |
| paddy@23 | 58 |
| paddy@23 | 59 // The base path of documentation |
| paddy@23 | 60 DocumentationDomain string |
| paddy@23 | 61 |
| paddy@23 | 62 SessionLength time.Duration |
| paddy@23 | 63 RequestIPHeader string |
| paddy@23 | 64 LoginRedirectDomain string |
| paddy@23 | 65 } |
| paddy@23 | 66 |
| paddy@23 | 67 // NewServerConfig returns a new ServerConfig with default configuration |
| paddy@23 | 68 func NewServerConfig() ServerConfig { |
| paddy@23 | 69 return ServerConfig{ |
| paddy@23 | 70 AuthorizationExpiration: 250, |
| paddy@23 | 71 AccessExpiration: 3600, |
| paddy@23 | 72 TokenType: "bearer", |
| paddy@23 | 73 AllowedAuthorizeTypes: AllowedAuthorizeType{CodeAuthRT}, |
| paddy@23 | 74 AllowedAccessTypes: AllowedAccessType{AuthorizationCodeGrant}, |
| paddy@23 | 75 ErrorStatusCode: 200, |
| paddy@23 | 76 AllowClientSecretInParams: false, |
| paddy@23 | 77 AllowGetAccessRequest: false, |
| paddy@23 | 78 } |
| paddy@23 | 79 } |