AuthURL returns the oauth auth url for github oauth authentication.
(state string, clientID string, callback string)
| 87 | |
| 88 | // AuthURL returns the oauth auth url for github oauth authentication. |
| 89 | func (a *AdminAuth) AuthURL(state string, clientID string, callback string) (realState string, authURL string) { |
| 90 | if a.OAuthEnabled() { |
| 91 | var opts []oauth2.AuthCodeOption |
| 92 | |
| 93 | if callback != "" { |
| 94 | opts = append(opts, oauth2.SetAuthURLParam("redirect_uri", callback)) |
| 95 | } |
| 96 | |
| 97 | var ( |
| 98 | oauthCfg *oauth2.Config |
| 99 | ok bool |
| 100 | ) |
| 101 | |
| 102 | if oauthCfg, ok = a.oauthCfg[clientID]; !ok || clientID == "" { |
| 103 | oauthCfg = a.oauthCfg["default"] |
| 104 | } else { |
| 105 | // append client_id to state |
| 106 | state = state + ":" + clientID |
| 107 | } |
| 108 | |
| 109 | return state, oauthCfg.AuthCodeURL(state, opts...) |
| 110 | } |
| 111 | |
| 112 | return "", "" |
| 113 | } |
| 114 | |
| 115 | // HandleLogin returns the tokens for github oauth authentication. |
| 116 | func (a *AdminAuth) HandleLogin(ctx context.Context, state string, auth string) (userInfo *AdminUserInfo, err error) { |
no test coverage detected