You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm seeing some unexpected behavior while interacting with oauth2.Config & oauth2.Token objects.
My client targets a Google Cloud OAuth Client ID (via the Oauth Consent Screens service AKA OAuth Brands). My client uses a web app type credential which exists in the following format:
Creating a config from this always works fine. I then update the redirect URL, generate a randomized state string, and generate an AuthCodeURL, specifying the oauth2.AccessTypeOffline option.
/LocalFetchtokeninitiatesarequestfromthelocalhost; theuserisresponsiblefor// providing the state and auth code.func (tm*TokenManager) LocalFetchToken(ctxcontext.Context) (errerror) {
// Generate an opaque identifier by hex-digesting random bytes.stateBuf:=make([]byte, 32)
if_, err=rand.Reader.Read(stateBuf); err!=nil {
return
}
oauth_state:=hex.EncodeToString(stateBuf)
authCodeURL:=tm.config.AuthCodeURL(oauth_state, oauth2.AccessTypeOffline)
fmt.Printf("Please go to the following link in your browser to generate an auth code:\n\t%s\n", authCodeURL)
varcode, statestringfmt.Print("Authorization code:")
fmt.Scanln(&code)
fmt.Print("\nAuthorization state:")
fmt.Scanln(&state)
ifoauth_state!=state {
returnfmt.Errorf("states do not match")
}
token, err:=tm.config.Exchange(ctx, code)
iferr!=nil {
return
}
fmt.Printf("Token Refresh Token: %s\n", token.RefreshToken)
tm.token=tokenreturn
}
This is not producing Refresh tokens even with the oauth2.AccessTypeOffline option. In the past, this used to issue Refresh tokens.
According to the documentation on oauth2.AccessTypeOffline documentation:
// AccessTypeOnline and AccessTypeOffline are options passed// to the Options.AuthCodeURL method. They modify the// "access_type" field that gets sent in the URL returned by// AuthCodeURL.//// Online is the default if neither is specified. If your// application needs to refresh access tokens when the user// is not present at the browser, then use offline. This will// result in your application obtaining **a refresh token the**// **first time your application exchanges an authorization**// **code for a user.**AccessTypeOnlineAuthCodeOption=SetAuthURLParam("access_type", "online")
AccessTypeOfflineAuthCodeOption=SetAuthURLParam("access_type", "offline")
Regards,
The text was updated successfully, but these errors were encountered:
Perhaps I encountered a similar problem, only I have slightly different conditions. I use keycloak and log in using the code, but in response I receive a token without refreshToken
however, there are examples where it is clear that refreshToken is provided
Hi there,
I'm seeing some unexpected behavior while interacting with oauth2.Config & oauth2.Token objects.
My client targets a Google Cloud OAuth Client ID (via the Oauth Consent Screens service AKA OAuth Brands). My client uses a web app type credential which exists in the following format:
Creating a config from this always works fine. I then update the redirect URL, generate a randomized state string, and generate an AuthCodeURL, specifying the oauth2.AccessTypeOffline option.
This is not producing Refresh tokens even with the oauth2.AccessTypeOffline option. In the past, this used to issue Refresh tokens.
According to the documentation on oauth2.AccessTypeOffline documentation:
Regards,
The text was updated successfully, but these errors were encountered: