Debian Codegraph @

internal/oauth2/providers/google/config.go

raw
1 package google
2
3 import (
4 "slices"
5
6 "github.com/jkroepke/openvpn-auth-oauth2/v2/internal/oauth2/types"
7 "golang.org/x/oauth2"
8 )
9
10 // GetProviderConfig implements the [github.com/jkroepke/openvpn-auth-oauth2/internal/oauth2.Provider] interface.
11 func (p Provider) GetProviderConfig() (types.ProviderConfig, error) {
12 providerConfig, err := p.Provider.GetProviderConfig()
13 if err != nil {
14 return types.ProviderConfig{}, err //nolint:wrapcheck
15 }
16
17 if p.Conf.OAuth2.Refresh.Enabled && p.Conf.OAuth2.Refresh.ValidateUser {
18 // Enable offline access to api a refresh token
19 providerConfig.AuthCodeOptions = []oauth2.AuthCodeOption{oauth2.AccessTypeOffline, oauth2.ApprovalForce}
20 }
21
22 providerConfig.Scopes = []string{types.ScopeEmail, types.ScopeProfile, types.ScopeOpenID}
23 if len(p.Conf.OAuth2.Validate.Groups) > 0 {
24 // Enable offline access to api a refresh token
25 providerConfig.Scopes = append(providerConfig.Scopes, "https://www.googleapis.com/auth/cloud-identity.groups.readonly")
26 }
27
28 providerConfig.Scopes = slices.Compact(providerConfig.Scopes)
29
30 return providerConfig, nil
31 }