Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http client is not auto relogin after refresh_token expired. #14

Open
nnluc073 opened this issue Oct 18, 2022 · 0 comments
Open

http client is not auto relogin after refresh_token expired. #14

nnluc073 opened this issue Oct 18, 2022 · 0 comments

Comments

@nnluc073
Copy link

config := oauth2.Config{
	ClientID:     enums.Env.KeycloakClientId,
	ClientSecret: enums.Env.KeycloakClientSecret,
	RedirectURL:  enums.Env.KeycloakRedirect,
	Endpoint: oauth2.Endpoint{
		TokenURL: fmt.Sprintf("%srealms/%s/protocol/openid-connect/token", enums.Env.KeycloakEndpoint, enums.Env.KeycloakRealm),
	},
}

// get a valid token from keycloak
ctx := context.Background()
token, err := config.PasswordCredentialsToken(ctx, enums.Env.KeycloakAdmin, enums.Env.KeycloakPassword)
if err != nil {
	panic(err)
}

// create a new http client that uses the token on every request
client := config.Client(ctx, token)

// create a new keycloak instance and provide the http client
clientKeycloak, err := keycloak.NewKeycloak(client, enums.Env.KeycloakEndpoint)

clientKeycloak can't call api after refresh_token expired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant