@@ -41,19 +41,49 @@ func GetSettings(conf *DexConfig) (*oidc.Settings, error) {
4141 if err != nil {
4242 return nil , err
4343 }
44+
45+ requestedScopes := conf .GetDexScopes ()
46+
4447 settings := & oidc.Settings {
4548 URL : conf .Url ,
4649 OIDCConfig : oidc.OIDCConfig {CLIClientID : conf .DexClientID ,
4750 ClientSecret : conf .DexClientSecret ,
4851 Issuer : proxyUrl ,
4952 ServerSecret : conf .ServerSecret ,
50- RequestedScopes : conf . DexScopes ,
53+ RequestedScopes : requestedScopes ,
5154 },
5255 UserSessionDuration : time .Duration (conf .UserSessionDurationSeconds ) * time .Second ,
5356 AdminPasswordMtime : conf .AdminPasswordMtime ,
5457 }
5558 return settings , nil
5659}
60+ func (conf * DexConfig ) GetDexScopes () []string {
61+ // passing empty array to get default scopes
62+ defaultScopes := oidc .GetScopesOrDefault ([]string {})
63+ additionalScopes := conf .DexScopes
64+
65+ // if no additional scopes configured return only default scopes
66+ if len (additionalScopes ) == 0 {
67+ return defaultScopes
68+ }
69+
70+ occurrenceMap := make (map [string ]struct {})
71+ finalScopes := make ([]string , 0 )
72+
73+ // first add all the default
74+ for _ , scope := range defaultScopes {
75+ occurrenceMap [scope ] = struct {}{}
76+ finalScopes = append (finalScopes , scope )
77+ }
78+ // append extra configs
79+ for _ , scope := range additionalScopes {
80+ if _ , exists := occurrenceMap [scope ]; ! exists {
81+ occurrenceMap [scope ] = struct {}{}
82+ finalScopes = append (finalScopes , scope )
83+ }
84+ }
85+ return finalScopes
86+ }
5787func getOidcClient (dexServerAddress string , settings * oidc.Settings , userVerifier oidc.UserVerifier , RedirectUrlSanitiser oidc.RedirectUrlSanitiser ) (* oidc.ClientApp , func (writer http.ResponseWriter , request * http.Request ), error ) {
5888 dexClient := & http.Client {
5989 Transport : & http.Transport {
0 commit comments