auth

Paddy 2014-08-16 Parent:9fe684b33b3d

21:51700827b6ee Go to Latest

auth/config.go

Redirect after login. After a successful login, redirect based on a query parameter. Only allow redirections to the domain listed in the config and its subdomains. If no redirect is specified, redirect to the root of the domain listed in the config.

History
1 package auth
3 import "time"
5 // AllowedAuthorizeType is a collection of allowed auth request types
6 type AllowedAuthorizeType []AuthorizeRequestType
8 // Exists returns true if the auth type exists in the list
9 func (t AllowedAuthorizeType) Exists(rt AuthorizeRequestType) bool {
10 for _, k := range t {
11 if k == rt {
12 return true
13 }
14 }
15 return false
16 }
18 // AllowedAccessType is a collection of allowed access request types
19 type AllowedAccessType []GrantType
21 // Exists returns true if the access type exists in the list
22 func (t AllowedAccessType) Exists(rt GrantType) bool {
23 for _, k := range t {
24 if k == rt {
25 return true
26 }
27 }
28 return false
29 }
31 // ServerConfig contains server configuration information
32 type ServerConfig struct {
33 // Authorization token expiration in seconds (default 5 minutes)
34 AuthorizationExpiration int32
36 // Access token expiration in seconds (default 1 hour)
37 AccessExpiration int32
39 // Token type to return
40 TokenType string
42 // List of allowed authorize types (only CodeAuthRT by default)
43 AllowedAuthorizeTypes AllowedAuthorizeType
45 // List of allowed access types (only AUTHORIZATION_CodeAuthRT by default)
46 AllowedAccessTypes AllowedAccessType
48 // HTTP status code to return for errors - default 200
49 // Only used if response was created from server
50 ErrorStatusCode int
52 // If true allows client secret also in params, else only in
53 // Authorization header - default false
54 AllowClientSecretInParams bool
56 // If true allows access request using GET, else only POST - default false
57 AllowGetAccessRequest bool
59 // The base path of documentation
60 DocumentationDomain string
62 SessionLength time.Duration
63 RequestIPHeader string
64 LoginRedirectDomain string
65 }
67 // NewServerConfig returns a new ServerConfig with default configuration
68 func NewServerConfig() ServerConfig {
69 return ServerConfig{
70 AuthorizationExpiration: 250,
71 AccessExpiration: 3600,
72 TokenType: "bearer",
73 AllowedAuthorizeTypes: AllowedAuthorizeType{CodeAuthRT},
74 AllowedAccessTypes: AllowedAccessType{AuthorizationCodeGrant},
75 ErrorStatusCode: 200,
76 AllowClientSecretInParams: false,
77 AllowGetAccessRequest: false,
78 }
79 }