NewServer returns a new OAuth server on top of the given store.
(c *component.Component, store oauth_store.TransactionalInterface, config Config, cspFunc func(config *Config, nonce string) string)
| 65 | |
| 66 | // NewServer returns a new OAuth server on top of the given store. |
| 67 | func NewServer(c *component.Component, store oauth_store.TransactionalInterface, config Config, cspFunc func(config *Config, nonce string) string) (Server, error) { |
| 68 | s := &server{ |
| 69 | c: c, |
| 70 | config: config, |
| 71 | store: store, |
| 72 | session: session.Session{ |
| 73 | Store: &sessionStore{store}, |
| 74 | CookieMaxAge: config.Login.SessionTTL, |
| 75 | }, |
| 76 | generateCSP: cspFunc, |
| 77 | schemaDecoder: schema.NewDecoder(), |
| 78 | } |
| 79 | s.schemaDecoder.IgnoreUnknownKeys(true) |
| 80 | |
| 81 | if s.config.Mount == "" { |
| 82 | s.config.Mount = s.config.UI.MountPath() |
| 83 | } |
| 84 | |
| 85 | s.osinConfig = &osin.ServerConfig{ |
| 86 | AuthorizationExpiration: int32((5 * time.Minute).Seconds()), |
| 87 | AccessExpiration: int32(time.Hour.Seconds()), |
| 88 | TokenType: "bearer", |
| 89 | AllowedAuthorizeTypes: osin.AllowedAuthorizeType{ |
| 90 | osin.CODE, |
| 91 | }, |
| 92 | AllowedAccessTypes: osin.AllowedAccessType{ |
| 93 | osin.AUTHORIZATION_CODE, |
| 94 | osin.REFRESH_TOKEN, |
| 95 | osin.PASSWORD, |
| 96 | }, |
| 97 | ErrorStatusCode: http.StatusBadRequest, |
| 98 | AllowClientSecretInParams: true, |
| 99 | RedirectUriSeparator: redirectURISeparator, |
| 100 | RetainTokenAfterRefresh: false, |
| 101 | } |
| 102 | |
| 103 | return s, nil |
| 104 | } |
| 105 | |
| 106 | type ctxKeyType struct{} |
| 107 |