mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-24 05:33:40 +09:00
Support webauthn (#17957)
Migrate from U2F to Webauthn Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
co-authored by
Andrew Thornton
6543
wxiaoguang
parent
8808293247
commit
35c3553870
+18
-3
@@ -25,6 +25,12 @@ func New(clientKey, secret, callbackURL string, scopes ...string) *Provider {
|
||||
Secret: secret,
|
||||
CallbackURL: callbackURL,
|
||||
providerName: "google",
|
||||
|
||||
// We can get a refresh token from Google by this option.
|
||||
// See https://developers.google.com/identity/protocols/oauth2/openid-connect#access-type-param
|
||||
authCodeOptions: []oauth2.AuthCodeOption{
|
||||
oauth2.AccessTypeOffline,
|
||||
},
|
||||
}
|
||||
p.config = newConfig(p, scopes)
|
||||
return p
|
||||
@@ -86,6 +92,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
|
||||
Provider: p.Name(),
|
||||
RefreshToken: sess.RefreshToken,
|
||||
ExpiresAt: sess.ExpiresAt,
|
||||
IDToken: sess.IDToken,
|
||||
}
|
||||
|
||||
if user.AccessToken == "" {
|
||||
@@ -139,9 +146,7 @@ func newConfig(provider *Provider, scopes []string) *oauth2.Config {
|
||||
}
|
||||
|
||||
if len(scopes) > 0 {
|
||||
for _, scope := range scopes {
|
||||
c.Scopes = append(c.Scopes, scope)
|
||||
}
|
||||
c.Scopes = append(c.Scopes, scopes...)
|
||||
} else {
|
||||
c.Scopes = []string{"email"}
|
||||
}
|
||||
@@ -194,3 +199,13 @@ func (p *Provider) SetLoginHint(loginHint string) {
|
||||
}
|
||||
p.authCodeOptions = append(p.authCodeOptions, oauth2.SetAuthURLParam("login_hint", loginHint))
|
||||
}
|
||||
|
||||
// SetAccessType sets the access_type parameter for the google OAuth call.
|
||||
// If an access token is being requested, the client does not receive a refresh token unless a value of offline is specified.
|
||||
// See https://developers.google.com/identity/protocols/oauth2/openid-connect#access-type-param
|
||||
func (p *Provider) SetAccessType(at string) {
|
||||
if at == "" {
|
||||
return
|
||||
}
|
||||
p.authCodeOptions = append(p.authCodeOptions, oauth2.SetAuthURLParam("access_type", at))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user