mirror of
https://github.com/zitadel/oidc.git
synced 2026-05-01 15:39:32 -05:00
feat: add rp.RefreshAccessToken (#198)
* chore: make tokenEndpointCaller public * add RelyingParty function * undo changes made by gofumpt * undo more gofumpt changes * undo more gofumpt changes
This commit is contained in:
@@ -48,16 +48,16 @@ func Discover(issuer string, httpClient *http.Client, wellKnownUrl ...string) (*
|
||||
return discoveryConfig, nil
|
||||
}
|
||||
|
||||
type tokenEndpointCaller interface {
|
||||
type TokenEndpointCaller interface {
|
||||
TokenEndpoint() string
|
||||
HttpClient() *http.Client
|
||||
}
|
||||
|
||||
func CallTokenEndpoint(request interface{}, caller tokenEndpointCaller) (newToken *oauth2.Token, err error) {
|
||||
func CallTokenEndpoint(request interface{}, caller TokenEndpointCaller) (newToken *oauth2.Token, err error) {
|
||||
return callTokenEndpoint(request, nil, caller)
|
||||
}
|
||||
|
||||
func callTokenEndpoint(request interface{}, authFn interface{}, caller tokenEndpointCaller) (newToken *oauth2.Token, err error) {
|
||||
func callTokenEndpoint(request interface{}, authFn interface{}, caller TokenEndpointCaller) (newToken *oauth2.Token, err error) {
|
||||
req, err := httphelper.FormRequest(caller.TokenEndpoint(), request, Encoder, authFn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"github.com/zitadel/oidc/pkg/oidc"
|
||||
)
|
||||
|
||||
//JWTProfileExchange handles the oauth2 jwt profile exchange
|
||||
func JWTProfileExchange(jwtProfileGrantRequest *oidc.JWTProfileGrantRequest, caller tokenEndpointCaller) (*oauth2.Token, error) {
|
||||
// JWTProfileExchange handles the oauth2 jwt profile exchange
|
||||
func JWTProfileExchange(jwtProfileGrantRequest *oidc.JWTProfileGrantRequest, caller TokenEndpointCaller) (*oauth2.Token, error) {
|
||||
return CallTokenEndpoint(jwtProfileGrantRequest, caller)
|
||||
}
|
||||
|
||||
|
||||
@@ -536,3 +536,23 @@ func WithClientAssertionJWT(clientAssertion string) CodeExchangeOpt {
|
||||
return client.ClientAssertionCodeOptions(clientAssertion)
|
||||
}
|
||||
}
|
||||
|
||||
type tokenEndpointCaller struct {
|
||||
RelyingParty
|
||||
}
|
||||
|
||||
func (t tokenEndpointCaller) TokenEndpoint() string {
|
||||
return t.OAuthConfig().Endpoint.TokenURL
|
||||
}
|
||||
|
||||
func RefreshAccessToken(rp RelyingParty, refreshToken, clientAssertion, clientAssertionType string) (*oauth2.Token, error) {
|
||||
request := oidc.RefreshTokenRequest{
|
||||
RefreshToken: refreshToken,
|
||||
Scopes: rp.OAuthConfig().Scopes,
|
||||
ClientID: rp.OAuthConfig().ClientID,
|
||||
ClientSecret: rp.OAuthConfig().ClientSecret,
|
||||
ClientAssertion: clientAssertion,
|
||||
ClientAssertionType: clientAssertionType,
|
||||
}
|
||||
return client.CallTokenEndpoint(request, tokenEndpointCaller{RelyingParty: rp})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user