@@ -60,6 +60,8 @@ func authEntryPoint(invocationCtx workflow.InvocationContext, _ []workflow.Data)
60
60
logger := invocationCtx .GetEnhancedLogger ()
61
61
engine := invocationCtx .GetEngine ()
62
62
63
+ config .ClearCache ()
64
+
63
65
httpClient := invocationCtx .GetNetworkAccess ().GetUnauthorizedHttpClient ()
64
66
authenticator := auth .NewOAuth2AuthenticatorWithOpts (
65
67
config ,
@@ -107,10 +109,13 @@ func entryPointDI(invocationCtx workflow.InvocationContext, logger *zerolog.Logg
107
109
logger .Printf ("Authentication Type: %s" , authType )
108
110
analytics .AddExtensionStringValue (authTypeParameter , authType )
109
111
110
- if strings .EqualFold (authType , auth .AUTH_TYPE_OAUTH ) { // OAUTH flow
111
- logger .Printf ("Unset legacy token key %q from config" , configuration .AUTHENTICATION_TOKEN )
112
- config .Unset (configuration .AUTHENTICATION_TOKEN )
112
+ existingSnykToken := config .GetString (configuration .AUTHENTICATION_TOKEN )
113
+ // always attempt to clear existing tokens before triggering auth
114
+ logger .Print ("Unset existing auth keys" )
115
+ config .Unset (configuration .AUTHENTICATION_TOKEN )
116
+ config .Unset (auth .CONFIG_KEY_OAUTH_TOKEN )
113
117
118
+ if strings .EqualFold (authType , auth .AUTH_TYPE_OAUTH ) { // OAUTH flow
114
119
headless := config .GetBool (headlessFlag )
115
120
logger .Printf ("Headless: %v" , headless )
116
121
@@ -125,25 +130,19 @@ func entryPointDI(invocationCtx workflow.InvocationContext, logger *zerolog.Logg
125
130
}
126
131
} else if strings .EqualFold (authType , auth .AUTH_TYPE_PAT ) { // PAT flow
127
132
engine .GetConfiguration ().PersistInStorage (auth .CONFIG_KEY_TOKEN )
128
-
129
- oldToken := config .GetString (configuration .AUTHENTICATION_TOKEN )
130
133
pat := config .GetString (ConfigurationNewAuthenticationToken )
131
134
132
- logger .Print ("Unset existing auth keys from config" )
133
- config .Unset (auth .CONFIG_KEY_OAUTH_TOKEN )
134
- config .Unset (configuration .AUTHENTICATION_TOKEN )
135
-
136
135
logger .Print ("Validating pat" )
137
136
whoamiConfig := config .Clone ()
138
- // we don't want to use the cache here, so this is a workaround
139
137
whoamiConfig .ClearCache ()
138
+ // we don't want to use the cache here, so this is a workaround
140
139
whoamiConfig .Set (configuration .FLAG_EXPERIMENTAL , true )
141
140
whoamiConfig .Set (configuration .AUTHENTICATION_TOKEN , pat )
142
141
_ , whoamiErr := engine .InvokeWithConfig (workflow .NewWorkflowIdentifier ("whoami" ), whoamiConfig )
143
142
if whoamiErr != nil {
144
143
// reset config file
145
- if len (oldToken ) > 0 {
146
- config .Set (auth .CONFIG_KEY_TOKEN , oldToken )
144
+ if len (existingSnykToken ) > 0 {
145
+ config .Set (auth .CONFIG_KEY_TOKEN , existingSnykToken )
147
146
}
148
147
return whoamiErr
149
148
}
@@ -158,9 +157,6 @@ func entryPointDI(invocationCtx workflow.InvocationContext, logger *zerolog.Logg
158
157
logger .Debug ().Err (err ).Msg ("Failed to output authenticated message" )
159
158
}
160
159
} else { // LEGACY flow
161
- logger .Printf ("Unset oauth key %q from config" , auth .CONFIG_KEY_OAUTH_TOKEN )
162
- config .Unset (auth .CONFIG_KEY_OAUTH_TOKEN )
163
-
164
160
config .Set (configuration .RAW_CMD_ARGS , os .Args [1 :])
165
161
config .Set (configuration .WORKFLOW_USE_STDIO , true )
166
162
config .Set (configuration .AUTHENTICATION_TOKEN , "" ) // clear token to avoid using it during authentication
0 commit comments