NewAdminAuth returns the admin oauth handler object.
(cfg *config.AdminAuthConfig)
| 55 | |
| 56 | // NewAdminAuth returns the admin oauth handler object. |
| 57 | func NewAdminAuth(cfg *config.AdminAuthConfig) (a *AdminAuth) { |
| 58 | a = &AdminAuth{ |
| 59 | cfg: cfg, |
| 60 | oauthCfg: make(map[string]*oauth2.Config), |
| 61 | } |
| 62 | |
| 63 | if a.cfg != nil && a.cfg.OAuthEnabled { |
| 64 | // set default as the first one |
| 65 | for idx, clientID := range a.cfg.GithubAppID { |
| 66 | singleCfg := &oauth2.Config{ |
| 67 | ClientID: clientID, |
| 68 | ClientSecret: a.cfg.GithubAppSecret[idx], |
| 69 | Endpoint: github.Endpoint, |
| 70 | } |
| 71 | |
| 72 | if idx == 0 { |
| 73 | a.oauthCfg["default"] = singleCfg |
| 74 | } |
| 75 | |
| 76 | a.oauthCfg[clientID] = singleCfg |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return |
| 81 | } |
| 82 | |
| 83 | // OAuthEnabled returns if oauth is enabled for administration. |
| 84 | func (a *AdminAuth) OAuthEnabled() bool { |