mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-30 16:08:56 +00:00
fix: set refresh token in the RetrieveIdentityIntentResponse (#11613)
# Which Problems Are Solved This PR adds support for storing and retrieving refresh tokens from external identity providers during the IDP intent flow. # How the Problems Are Solved * Updated `idp.proto` (v2 and v2beta): added an optional `refresh_token` field to `IDPOAuthAccessInformation`, which, in turn, is used in `RetrieveIdentityProviderIntentResponse` * Added the `IDPRefreshToken` field to the IDP intent `SucceededEvent` struct, and updated the corresponding constructor to set the refresh token * Added the `IDPRefreshToken` field to `IDPIntentWriteModel`, and updated `reduceOAuthSucceededEvent` to populate refresh token from events * Updated `tokensForSucceededIDPIntent` function to extract and encrypt the refresh token from IDP session, if set * Updated `idpOAuthTokensToPb` function to decrypt refresh token before returning to clients * Updated unit and integration tests # Additional Changes Updated the link to the JWT IDP docs linked in the Console # Additional Context - Closes https://github.com/zitadel/zitadel/issues/11047
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
[configureProvider]="(justCreated$ | async) === ''"
|
[configureProvider]="(justCreated$ | async) === ''"
|
||||||
[configureTitle]="'DESCRIPTIONS.SETTINGS.IDPS.JWT.TITLE' | translate"
|
[configureTitle]="'DESCRIPTIONS.SETTINGS.IDPS.JWT.TITLE' | translate"
|
||||||
[configureDescription]="'DESCRIPTIONS.SETTINGS.IDPS.JWT.DESCRIPTION' | translate"
|
[configureDescription]="'DESCRIPTIONS.SETTINGS.IDPS.JWT.DESCRIPTION' | translate"
|
||||||
configureLink="https://zitadel.com/docs/guides/integrate/identity-providers/jwt-idp"
|
configureLink="https://zitadel.com/docs/guides/integrate/identity-providers/jwt_idp"
|
||||||
[autofillLink]="autofillLink$ | async"
|
[autofillLink]="autofillLink$ | async"
|
||||||
[activateLink]="activateLink$ | async"
|
[activateLink]="activateLink$ | async"
|
||||||
[expanded]="!!(expandWhatNow$ | async)"
|
[expanded]="!!(expandWhatNow$ | async)"
|
||||||
|
|||||||
@@ -425,8 +425,9 @@ func TestServer_RetrieveIdentityProviderIntent(t *testing.T) {
|
|||||||
IdpInformation: &user.IDPInformation{
|
IdpInformation: &user.IDPInformation{
|
||||||
Access: &user.IDPInformation_Oauth{
|
Access: &user.IDPInformation_Oauth{
|
||||||
Oauth: &user.IDPOAuthAccessInformation{
|
Oauth: &user.IDPOAuthAccessInformation{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
IdToken: gu.Ptr("idToken"),
|
RefreshToken: gu.Ptr("refreshToken"),
|
||||||
|
IdToken: gu.Ptr("idToken"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
IdpId: oauthIdpID,
|
IdpId: oauthIdpID,
|
||||||
@@ -476,8 +477,9 @@ func TestServer_RetrieveIdentityProviderIntent(t *testing.T) {
|
|||||||
IdpInformation: &user.IDPInformation{
|
IdpInformation: &user.IDPInformation{
|
||||||
Access: &user.IDPInformation_Oauth{
|
Access: &user.IDPInformation_Oauth{
|
||||||
Oauth: &user.IDPOAuthAccessInformation{
|
Oauth: &user.IDPOAuthAccessInformation{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
IdToken: gu.Ptr("idToken"),
|
RefreshToken: gu.Ptr("refreshToken"),
|
||||||
|
IdToken: gu.Ptr("idToken"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
IdpId: oauthIdpID,
|
IdpId: oauthIdpID,
|
||||||
@@ -543,8 +545,9 @@ func TestServer_RetrieveIdentityProviderIntent(t *testing.T) {
|
|||||||
IdpInformation: &user.IDPInformation{
|
IdpInformation: &user.IDPInformation{
|
||||||
Access: &user.IDPInformation_Oauth{
|
Access: &user.IDPInformation_Oauth{
|
||||||
Oauth: &user.IDPOAuthAccessInformation{
|
Oauth: &user.IDPOAuthAccessInformation{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
IdToken: gu.Ptr("idToken"),
|
RefreshToken: gu.Ptr("refreshToken"),
|
||||||
|
IdToken: gu.Ptr("idToken"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
IdpId: azureIdpID,
|
IdpId: azureIdpID,
|
||||||
@@ -601,8 +604,9 @@ func TestServer_RetrieveIdentityProviderIntent(t *testing.T) {
|
|||||||
IdpInformation: &user.IDPInformation{
|
IdpInformation: &user.IDPInformation{
|
||||||
Access: &user.IDPInformation_Oauth{
|
Access: &user.IDPInformation_Oauth{
|
||||||
Oauth: &user.IDPOAuthAccessInformation{
|
Oauth: &user.IDPOAuthAccessInformation{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
IdToken: gu.Ptr("idToken"),
|
RefreshToken: gu.Ptr("refreshToken"),
|
||||||
|
IdToken: gu.Ptr("idToken"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
IdpId: azureIdpID,
|
IdpId: azureIdpID,
|
||||||
@@ -657,8 +661,9 @@ func TestServer_RetrieveIdentityProviderIntent(t *testing.T) {
|
|||||||
IdpInformation: &user.IDPInformation{
|
IdpInformation: &user.IDPInformation{
|
||||||
Access: &user.IDPInformation_Oauth{
|
Access: &user.IDPInformation_Oauth{
|
||||||
Oauth: &user.IDPOAuthAccessInformation{
|
Oauth: &user.IDPOAuthAccessInformation{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
IdToken: gu.Ptr("idToken"),
|
RefreshToken: gu.Ptr("refreshToken"),
|
||||||
|
IdToken: gu.Ptr("idToken"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
IdpId: oidcIdpID,
|
IdpId: oidcIdpID,
|
||||||
@@ -707,8 +712,9 @@ func TestServer_RetrieveIdentityProviderIntent(t *testing.T) {
|
|||||||
IdpInformation: &user.IDPInformation{
|
IdpInformation: &user.IDPInformation{
|
||||||
Access: &user.IDPInformation_Oauth{
|
Access: &user.IDPInformation_Oauth{
|
||||||
Oauth: &user.IDPOAuthAccessInformation{
|
Oauth: &user.IDPOAuthAccessInformation{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
IdToken: gu.Ptr("idToken"),
|
RefreshToken: gu.Ptr("refreshToken"),
|
||||||
|
IdToken: gu.Ptr("idToken"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
IdpId: oidcIdpID,
|
IdpId: oidcIdpID,
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ func idpIntentToIDPIntentPb(intent *command.IDPIntentWriteModel, alg crypto.Encr
|
|||||||
information.Details = intentToDetailsPb(intent)
|
information.Details = intentToDetailsPb(intent)
|
||||||
// OAuth / OIDC
|
// OAuth / OIDC
|
||||||
if intent.IDPIDToken != "" || intent.IDPAccessToken != nil {
|
if intent.IDPIDToken != "" || intent.IDPAccessToken != nil {
|
||||||
information.IdpInformation.Access, err = idpOAuthTokensToPb(intent.IDPIDToken, intent.IDPAccessToken, alg)
|
information.IdpInformation.Access, err = idpOAuthTokensToPb(intent.IDPIDToken, intent.IDPAccessToken, intent.IDPRefreshToken, alg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -274,7 +274,7 @@ func idpIntentToIDPIntentPb(intent *command.IDPIntentWriteModel, alg crypto.Encr
|
|||||||
return information, nil
|
return information, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func idpOAuthTokensToPb(idpIDToken string, idpAccessToken *crypto.CryptoValue, alg crypto.EncryptionAlgorithm) (_ *user.IDPInformation_Oauth, err error) {
|
func idpOAuthTokensToPb(idpIDToken string, idpAccessToken, idpRefreshToken *crypto.CryptoValue, alg crypto.EncryptionAlgorithm) (_ *user.IDPInformation_Oauth, err error) {
|
||||||
var idToken *string
|
var idToken *string
|
||||||
if idpIDToken != "" {
|
if idpIDToken != "" {
|
||||||
idToken = &idpIDToken
|
idToken = &idpIDToken
|
||||||
@@ -286,10 +286,19 @@ func idpOAuthTokensToPb(idpIDToken string, idpAccessToken *crypto.CryptoValue, a
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var refreshToken *string
|
||||||
|
if idpRefreshToken != nil {
|
||||||
|
decryptedRefreshToken, err := crypto.DecryptString(idpRefreshToken, alg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
refreshToken = &decryptedRefreshToken
|
||||||
|
}
|
||||||
return &user.IDPInformation_Oauth{
|
return &user.IDPInformation_Oauth{
|
||||||
Oauth: &user.IDPOAuthAccessInformation{
|
Oauth: &user.IDPOAuthAccessInformation{
|
||||||
AccessToken: accessToken,
|
AccessToken: accessToken,
|
||||||
IdToken: idToken,
|
RefreshToken: refreshToken,
|
||||||
|
IdToken: idToken,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2299,8 +2299,9 @@ func TestServer_RetrieveIdentityProviderIntent(t *testing.T) {
|
|||||||
IdpInformation: &user.IDPInformation{
|
IdpInformation: &user.IDPInformation{
|
||||||
Access: &user.IDPInformation_Oauth{
|
Access: &user.IDPInformation_Oauth{
|
||||||
Oauth: &user.IDPOAuthAccessInformation{
|
Oauth: &user.IDPOAuthAccessInformation{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
IdToken: gu.Ptr("idToken"),
|
RefreshToken: gu.Ptr("refreshToken"),
|
||||||
|
IdToken: gu.Ptr("idToken"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
IdpId: oauthIdpID,
|
IdpId: oauthIdpID,
|
||||||
@@ -2339,8 +2340,9 @@ func TestServer_RetrieveIdentityProviderIntent(t *testing.T) {
|
|||||||
IdpInformation: &user.IDPInformation{
|
IdpInformation: &user.IDPInformation{
|
||||||
Access: &user.IDPInformation_Oauth{
|
Access: &user.IDPInformation_Oauth{
|
||||||
Oauth: &user.IDPOAuthAccessInformation{
|
Oauth: &user.IDPOAuthAccessInformation{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
IdToken: gu.Ptr("idToken"),
|
RefreshToken: gu.Ptr("refreshToken"),
|
||||||
|
IdToken: gu.Ptr("idToken"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
IdpId: oauthIdpID,
|
IdpId: oauthIdpID,
|
||||||
@@ -2401,8 +2403,9 @@ func TestServer_RetrieveIdentityProviderIntent(t *testing.T) {
|
|||||||
IdpInformation: &user.IDPInformation{
|
IdpInformation: &user.IDPInformation{
|
||||||
Access: &user.IDPInformation_Oauth{
|
Access: &user.IDPInformation_Oauth{
|
||||||
Oauth: &user.IDPOAuthAccessInformation{
|
Oauth: &user.IDPOAuthAccessInformation{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
IdToken: gu.Ptr("idToken"),
|
RefreshToken: gu.Ptr("refreshToken"),
|
||||||
|
IdToken: gu.Ptr("idToken"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
IdpId: oidcIdpID,
|
IdpId: oidcIdpID,
|
||||||
@@ -2439,8 +2442,9 @@ func TestServer_RetrieveIdentityProviderIntent(t *testing.T) {
|
|||||||
IdpInformation: &user.IDPInformation{
|
IdpInformation: &user.IDPInformation{
|
||||||
Access: &user.IDPInformation_Oauth{
|
Access: &user.IDPInformation_Oauth{
|
||||||
Oauth: &user.IDPOAuthAccessInformation{
|
Oauth: &user.IDPOAuthAccessInformation{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
IdToken: gu.Ptr("idToken"),
|
RefreshToken: gu.Ptr("refreshToken"),
|
||||||
|
IdToken: gu.Ptr("idToken"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
IdpId: oidcIdpID,
|
IdpId: oidcIdpID,
|
||||||
|
|||||||
@@ -522,7 +522,7 @@ func idpIntentToIDPIntentPb(intent *command.IDPIntentWriteModel, alg crypto.Encr
|
|||||||
UserId: intent.UserID,
|
UserId: intent.UserID,
|
||||||
}
|
}
|
||||||
if intent.IDPIDToken != "" || intent.IDPAccessToken != nil {
|
if intent.IDPIDToken != "" || intent.IDPAccessToken != nil {
|
||||||
information.IdpInformation.Access, err = idpOAuthTokensToPb(intent.IDPIDToken, intent.IDPAccessToken, alg)
|
information.IdpInformation.Access, err = idpOAuthTokensToPb(intent.IDPIDToken, intent.IDPAccessToken, intent.IDPRefreshToken, alg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -547,7 +547,7 @@ func idpIntentToIDPIntentPb(intent *command.IDPIntentWriteModel, alg crypto.Encr
|
|||||||
return connect.NewResponse(information), nil
|
return connect.NewResponse(information), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func idpOAuthTokensToPb(idpIDToken string, idpAccessToken *crypto.CryptoValue, alg crypto.EncryptionAlgorithm) (_ *user.IDPInformation_Oauth, err error) {
|
func idpOAuthTokensToPb(idpIDToken string, idpAccessToken, idpRefreshToken *crypto.CryptoValue, alg crypto.EncryptionAlgorithm) (_ *user.IDPInformation_Oauth, err error) {
|
||||||
var idToken *string
|
var idToken *string
|
||||||
if idpIDToken != "" {
|
if idpIDToken != "" {
|
||||||
idToken = &idpIDToken
|
idToken = &idpIDToken
|
||||||
@@ -559,10 +559,19 @@ func idpOAuthTokensToPb(idpIDToken string, idpAccessToken *crypto.CryptoValue, a
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var refreshToken *string
|
||||||
|
if idpRefreshToken != nil {
|
||||||
|
decryptedRefreshToken, err := crypto.DecryptString(idpRefreshToken, alg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
refreshToken = &decryptedRefreshToken
|
||||||
|
}
|
||||||
return &user.IDPInformation_Oauth{
|
return &user.IDPInformation_Oauth{
|
||||||
Oauth: &user.IDPOAuthAccessInformation{
|
Oauth: &user.IDPOAuthAccessInformation{
|
||||||
AccessToken: accessToken,
|
AccessToken: accessToken,
|
||||||
IdToken: idToken,
|
RefreshToken: refreshToken,
|
||||||
|
IdToken: idToken,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ func (c *Commands) SucceedIDPIntent(ctx context.Context, writeModel *IDPIntentWr
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
accessToken, idToken, err := tokensForSucceededIDPIntent(idpSession, c.idpConfigEncryption)
|
accessToken, refreshToken, idToken, err := tokensForSucceededIDPIntent(idpSession, c.idpConfigEncryption)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -186,6 +186,7 @@ func (c *Commands) SucceedIDPIntent(ctx context.Context, writeModel *IDPIntentWr
|
|||||||
idpUser.GetPreferredUsername(),
|
idpUser.GetPreferredUsername(),
|
||||||
userID,
|
userID,
|
||||||
accessToken,
|
accessToken,
|
||||||
|
refreshToken,
|
||||||
idToken,
|
idToken,
|
||||||
idpSession.ExpiresAt(),
|
idpSession.ExpiresAt(),
|
||||||
)
|
)
|
||||||
@@ -295,8 +296,9 @@ func (c *Commands) GetIntentWriteModel(ctx context.Context, id, resourceOwner st
|
|||||||
return writeModel, err
|
return writeModel, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// tokensForSucceededIDPIntent extracts the oidc.Tokens if available (and encrypts the access_token) for the succeeded event payload
|
// tokensForSucceededIDPIntent extracts the oidc.Tokens if available for the succeeded event payload.
|
||||||
func tokensForSucceededIDPIntent(session idp.Session, encryptionAlg crypto.EncryptionAlgorithm) (*crypto.CryptoValue, string, error) {
|
// It also encrypts the access token and refresh token (if set).
|
||||||
|
func tokensForSucceededIDPIntent(session idp.Session, encryptionAlg crypto.EncryptionAlgorithm) (*crypto.CryptoValue, *crypto.CryptoValue, string, error) {
|
||||||
var tokens *oidc.Tokens[*oidc.IDTokenClaims]
|
var tokens *oidc.Tokens[*oidc.IDTokenClaims]
|
||||||
switch s := session.(type) {
|
switch s := session.(type) {
|
||||||
case *oauth.Session:
|
case *oauth.Session:
|
||||||
@@ -312,11 +314,25 @@ func tokensForSucceededIDPIntent(session idp.Session, encryptionAlg crypto.Encry
|
|||||||
case *apple.Session:
|
case *apple.Session:
|
||||||
tokens = s.Tokens
|
tokens = s.Tokens
|
||||||
default:
|
default:
|
||||||
return nil, "", nil
|
return nil, nil, "", nil
|
||||||
|
}
|
||||||
|
if tokens == nil {
|
||||||
|
return nil, nil, "", nil
|
||||||
}
|
}
|
||||||
if tokens.Token == nil || tokens.AccessToken == "" {
|
if tokens.Token == nil || tokens.AccessToken == "" {
|
||||||
return nil, tokens.IDToken, nil
|
return nil, nil, tokens.IDToken, nil
|
||||||
}
|
}
|
||||||
accessToken, err := crypto.Encrypt([]byte(tokens.AccessToken), encryptionAlg)
|
accessToken, err := crypto.Encrypt([]byte(tokens.AccessToken), encryptionAlg)
|
||||||
return accessToken, tokens.IDToken, err
|
if err != nil {
|
||||||
|
return nil, nil, tokens.IDToken, err
|
||||||
|
}
|
||||||
|
var refreshToken *crypto.CryptoValue
|
||||||
|
if tokens.RefreshToken != "" {
|
||||||
|
refreshToken, err = crypto.Encrypt([]byte(tokens.RefreshToken), encryptionAlg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, tokens.IDToken, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return accessToken, refreshToken, tokens.IDToken, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ type IDPIntentWriteModel struct {
|
|||||||
UserID string
|
UserID string
|
||||||
LoginHint string
|
LoginHint string
|
||||||
|
|
||||||
IDPAccessToken *crypto.CryptoValue
|
IDPAccessToken *crypto.CryptoValue
|
||||||
IDPIDToken string
|
IDPRefreshToken *crypto.CryptoValue
|
||||||
|
IDPIDToken string
|
||||||
|
|
||||||
IDPEntryAttributes map[string][]string
|
IDPEntryAttributes map[string][]string
|
||||||
|
|
||||||
@@ -131,6 +132,7 @@ func (wm *IDPIntentWriteModel) reduceOAuthSucceededEvent(e *idpintent.SucceededE
|
|||||||
wm.IDPUserID = e.IDPUserID
|
wm.IDPUserID = e.IDPUserID
|
||||||
wm.IDPUserName = e.IDPUserName
|
wm.IDPUserName = e.IDPUserName
|
||||||
wm.IDPAccessToken = e.IDPAccessToken
|
wm.IDPAccessToken = e.IDPAccessToken
|
||||||
|
wm.IDPRefreshToken = e.IDPRefreshToken
|
||||||
wm.IDPIDToken = e.IDPIDToken
|
wm.IDPIDToken = e.IDPIDToken
|
||||||
wm.State = domain.IDPIntentStateSucceeded
|
wm.State = domain.IDPIntentStateSucceeded
|
||||||
wm.succeededAt = e.CreationDate()
|
wm.succeededAt = e.CreationDate()
|
||||||
|
|||||||
@@ -1105,6 +1105,12 @@ func TestCommands_SucceedIDPIntent(t *testing.T) {
|
|||||||
KeyID: "id",
|
KeyID: "id",
|
||||||
Crypted: []byte("accessToken"),
|
Crypted: []byte("accessToken"),
|
||||||
},
|
},
|
||||||
|
&crypto.CryptoValue{
|
||||||
|
CryptoType: crypto.TypeEncryption,
|
||||||
|
Algorithm: "enc",
|
||||||
|
KeyID: "id",
|
||||||
|
Crypted: []byte("refreshToken"),
|
||||||
|
},
|
||||||
"idToken",
|
"idToken",
|
||||||
time.Time{},
|
time.Time{},
|
||||||
)
|
)
|
||||||
@@ -1119,7 +1125,8 @@ func TestCommands_SucceedIDPIntent(t *testing.T) {
|
|||||||
idpSession: &openid.Session{
|
idpSession: &openid.Session{
|
||||||
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
||||||
Token: &oauth2.Token{
|
Token: &oauth2.Token{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
|
RefreshToken: "refreshToken",
|
||||||
},
|
},
|
||||||
IDToken: "idToken",
|
IDToken: "idToken",
|
||||||
},
|
},
|
||||||
@@ -1501,9 +1508,10 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
|||||||
encryptionAlg crypto.EncryptionAlgorithm
|
encryptionAlg crypto.EncryptionAlgorithm
|
||||||
}
|
}
|
||||||
type res struct {
|
type res struct {
|
||||||
accessToken *crypto.CryptoValue
|
accessToken *crypto.CryptoValue
|
||||||
idToken string
|
refreshToken *crypto.CryptoValue
|
||||||
err error
|
idToken string
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -1517,9 +1525,10 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
|||||||
crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||||
},
|
},
|
||||||
res{
|
res{
|
||||||
accessToken: nil,
|
accessToken: nil,
|
||||||
idToken: "",
|
refreshToken: nil,
|
||||||
err: nil,
|
idToken: "",
|
||||||
|
err: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1539,13 +1548,44 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
|||||||
}(),
|
}(),
|
||||||
},
|
},
|
||||||
res{
|
res{
|
||||||
accessToken: nil,
|
accessToken: nil,
|
||||||
idToken: "",
|
refreshToken: nil,
|
||||||
err: zerrors.ThrowInternal(nil, "id", "encryption failed"),
|
idToken: "",
|
||||||
|
err: zerrors.ThrowInternal(nil, "id", "encryption failed"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"oauth tokens",
|
"oauth tokens",
|
||||||
|
args{
|
||||||
|
&oauth.Session{
|
||||||
|
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
||||||
|
Token: &oauth2.Token{
|
||||||
|
AccessToken: "accessToken",
|
||||||
|
RefreshToken: "refreshToken",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||||
|
},
|
||||||
|
res{
|
||||||
|
accessToken: &crypto.CryptoValue{
|
||||||
|
CryptoType: crypto.TypeEncryption,
|
||||||
|
Algorithm: "enc",
|
||||||
|
KeyID: "id",
|
||||||
|
Crypted: []byte("accessToken"),
|
||||||
|
},
|
||||||
|
refreshToken: &crypto.CryptoValue{
|
||||||
|
CryptoType: crypto.TypeEncryption,
|
||||||
|
Algorithm: "enc",
|
||||||
|
KeyID: "id",
|
||||||
|
Crypted: []byte("refreshToken"),
|
||||||
|
},
|
||||||
|
idToken: "",
|
||||||
|
err: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"oauth tokens - no refresh token",
|
||||||
args{
|
args{
|
||||||
&oauth.Session{
|
&oauth.Session{
|
||||||
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
||||||
@@ -1563,8 +1603,9 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
|||||||
KeyID: "id",
|
KeyID: "id",
|
||||||
Crypted: []byte("accessToken"),
|
Crypted: []byte("accessToken"),
|
||||||
},
|
},
|
||||||
idToken: "",
|
refreshToken: nil,
|
||||||
err: nil,
|
idToken: "",
|
||||||
|
err: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1573,7 +1614,8 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
|||||||
&openid.Session{
|
&openid.Session{
|
||||||
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
||||||
Token: &oauth2.Token{
|
Token: &oauth2.Token{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
|
RefreshToken: "refreshToken",
|
||||||
},
|
},
|
||||||
IDToken: "idToken",
|
IDToken: "idToken",
|
||||||
},
|
},
|
||||||
@@ -1587,6 +1629,12 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
|||||||
KeyID: "id",
|
KeyID: "id",
|
||||||
Crypted: []byte("accessToken"),
|
Crypted: []byte("accessToken"),
|
||||||
},
|
},
|
||||||
|
refreshToken: &crypto.CryptoValue{
|
||||||
|
CryptoType: crypto.TypeEncryption,
|
||||||
|
Algorithm: "enc",
|
||||||
|
KeyID: "id",
|
||||||
|
Crypted: []byte("refreshToken"),
|
||||||
|
},
|
||||||
idToken: "idToken",
|
idToken: "idToken",
|
||||||
err: nil,
|
err: nil,
|
||||||
},
|
},
|
||||||
@@ -1602,9 +1650,10 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
|||||||
crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
||||||
},
|
},
|
||||||
res{
|
res{
|
||||||
accessToken: nil,
|
accessToken: nil,
|
||||||
idToken: "idToken",
|
refreshToken: nil,
|
||||||
err: nil,
|
idToken: "idToken",
|
||||||
|
err: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1628,8 +1677,9 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
|||||||
KeyID: "id",
|
KeyID: "id",
|
||||||
Crypted: []byte("accessToken"),
|
Crypted: []byte("accessToken"),
|
||||||
},
|
},
|
||||||
idToken: "",
|
refreshToken: nil,
|
||||||
err: nil,
|
idToken: "",
|
||||||
|
err: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1639,7 +1689,8 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
|||||||
OAuthSession: &oauth.Session{
|
OAuthSession: &oauth.Session{
|
||||||
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
||||||
Token: &oauth2.Token{
|
Token: &oauth2.Token{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
|
RefreshToken: "refreshToken",
|
||||||
},
|
},
|
||||||
IDToken: "idToken",
|
IDToken: "idToken",
|
||||||
},
|
},
|
||||||
@@ -1654,6 +1705,12 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
|||||||
KeyID: "id",
|
KeyID: "id",
|
||||||
Crypted: []byte("accessToken"),
|
Crypted: []byte("accessToken"),
|
||||||
},
|
},
|
||||||
|
refreshToken: &crypto.CryptoValue{
|
||||||
|
CryptoType: crypto.TypeEncryption,
|
||||||
|
Algorithm: "enc",
|
||||||
|
KeyID: "id",
|
||||||
|
Crypted: []byte("refreshToken"),
|
||||||
|
},
|
||||||
idToken: "idToken",
|
idToken: "idToken",
|
||||||
err: nil,
|
err: nil,
|
||||||
},
|
},
|
||||||
@@ -1661,9 +1718,10 @@ func Test_tokensForSucceededIDPIntent(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
gotAccessToken, gotIDToken, err := tokensForSucceededIDPIntent(tt.args.session, tt.args.encryptionAlg)
|
gotAccessToken, refreshToken, gotIDToken, err := tokensForSucceededIDPIntent(tt.args.session, tt.args.encryptionAlg)
|
||||||
require.ErrorIs(t, err, tt.res.err)
|
require.ErrorIs(t, err, tt.res.err)
|
||||||
assert.Equal(t, tt.res.accessToken, gotAccessToken)
|
assert.Equal(t, tt.res.accessToken, gotAccessToken)
|
||||||
|
assert.Equal(t, tt.res.refreshToken, refreshToken)
|
||||||
assert.Equal(t, tt.res.idToken, gotIDToken)
|
assert.Equal(t, tt.res.idToken, gotIDToken)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -742,6 +742,7 @@ func TestCommands_updateSession(t *testing.T) {
|
|||||||
"idpUserName",
|
"idpUserName",
|
||||||
"userID2",
|
"userID2",
|
||||||
nil,
|
nil,
|
||||||
|
nil,
|
||||||
"",
|
"",
|
||||||
time.Now().Add(time.Hour),
|
time.Now().Add(time.Hour),
|
||||||
),
|
),
|
||||||
@@ -823,6 +824,7 @@ func TestCommands_updateSession(t *testing.T) {
|
|||||||
"idpUsername",
|
"idpUsername",
|
||||||
"userID",
|
"userID",
|
||||||
nil,
|
nil,
|
||||||
|
nil,
|
||||||
"",
|
"",
|
||||||
time.Now().Add(time.Hour),
|
time.Now().Add(time.Hour),
|
||||||
),
|
),
|
||||||
@@ -878,6 +880,7 @@ func TestCommands_updateSession(t *testing.T) {
|
|||||||
"idpUsername",
|
"idpUsername",
|
||||||
"userID",
|
"userID",
|
||||||
nil,
|
nil,
|
||||||
|
nil,
|
||||||
"",
|
"",
|
||||||
time.Now().Add(-time.Hour),
|
time.Now().Add(-time.Hour),
|
||||||
),
|
),
|
||||||
@@ -928,6 +931,7 @@ func TestCommands_updateSession(t *testing.T) {
|
|||||||
"idpUsername",
|
"idpUsername",
|
||||||
"userID",
|
"userID",
|
||||||
nil,
|
nil,
|
||||||
|
nil,
|
||||||
"",
|
"",
|
||||||
time.Now().Add(time.Hour),
|
time.Now().Add(time.Hour),
|
||||||
),
|
),
|
||||||
@@ -1005,6 +1009,7 @@ func TestCommands_updateSession(t *testing.T) {
|
|||||||
"idpUsername",
|
"idpUsername",
|
||||||
"",
|
"",
|
||||||
nil,
|
nil,
|
||||||
|
nil,
|
||||||
"",
|
"",
|
||||||
time.Now().Add(time.Hour),
|
time.Now().Add(time.Hour),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -438,8 +438,9 @@ func createSuccessfulOAuthIntent(ctx context.Context, cmd *command.Commands, req
|
|||||||
idpSession := &oauth.Session{
|
idpSession := &oauth.Session{
|
||||||
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
||||||
Token: &oauth2.Token{
|
Token: &oauth2.Token{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
Expiry: req.Expiry,
|
RefreshToken: "refreshToken",
|
||||||
|
Expiry: req.Expiry,
|
||||||
},
|
},
|
||||||
IDToken: "idToken",
|
IDToken: "idToken",
|
||||||
},
|
},
|
||||||
@@ -476,8 +477,9 @@ func createSuccessfulAzureADIntent(ctx context.Context, cmd *command.Commands, r
|
|||||||
idpSession := &oauth.Session{
|
idpSession := &oauth.Session{
|
||||||
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
||||||
Token: &oauth2.Token{
|
Token: &oauth2.Token{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
Expiry: req.Expiry,
|
RefreshToken: "refreshToken",
|
||||||
|
Expiry: req.Expiry,
|
||||||
},
|
},
|
||||||
IDToken: "idToken",
|
IDToken: "idToken",
|
||||||
},
|
},
|
||||||
@@ -508,8 +510,9 @@ func createSuccessfulOIDCIntent(ctx context.Context, cmd *command.Commands, req
|
|||||||
idpSession := &openid.Session{
|
idpSession := &openid.Session{
|
||||||
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
||||||
Token: &oauth2.Token{
|
Token: &oauth2.Token{
|
||||||
AccessToken: "accessToken",
|
AccessToken: "accessToken",
|
||||||
Expiry: req.Expiry,
|
RefreshToken: "refreshToken",
|
||||||
|
Expiry: req.Expiry,
|
||||||
},
|
},
|
||||||
IDToken: "idToken",
|
IDToken: "idToken",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -82,9 +82,10 @@ type SucceededEvent struct {
|
|||||||
IDPUserName string `json:"idpUserName,omitempty"`
|
IDPUserName string `json:"idpUserName,omitempty"`
|
||||||
UserID string `json:"userId,omitempty"`
|
UserID string `json:"userId,omitempty"`
|
||||||
|
|
||||||
IDPAccessToken *crypto.CryptoValue `json:"idpAccessToken,omitempty"`
|
IDPAccessToken *crypto.CryptoValue `json:"idpAccessToken,omitempty"`
|
||||||
IDPIDToken string `json:"idpIdToken,omitempty"`
|
IDPRefreshToken *crypto.CryptoValue `json:"idpRefreshToken,omitempty"`
|
||||||
ExpiresAt time.Time `json:"expiresAt,omitempty"`
|
IDPIDToken string `json:"idpIdToken,omitempty"`
|
||||||
|
ExpiresAt time.Time `json:"expiresAt,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSucceededEvent(
|
func NewSucceededEvent(
|
||||||
@@ -95,6 +96,7 @@ func NewSucceededEvent(
|
|||||||
idpUserName,
|
idpUserName,
|
||||||
userID string,
|
userID string,
|
||||||
idpAccessToken *crypto.CryptoValue,
|
idpAccessToken *crypto.CryptoValue,
|
||||||
|
idpRefreshToken *crypto.CryptoValue,
|
||||||
idpIDToken string,
|
idpIDToken string,
|
||||||
expiresAt time.Time,
|
expiresAt time.Time,
|
||||||
) *SucceededEvent {
|
) *SucceededEvent {
|
||||||
@@ -104,13 +106,14 @@ func NewSucceededEvent(
|
|||||||
aggregate,
|
aggregate,
|
||||||
SucceededEventType,
|
SucceededEventType,
|
||||||
),
|
),
|
||||||
IDPUser: idpUser,
|
IDPUser: idpUser,
|
||||||
IDPUserID: idpUserID,
|
IDPUserID: idpUserID,
|
||||||
IDPUserName: idpUserName,
|
IDPUserName: idpUserName,
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
IDPAccessToken: idpAccessToken,
|
IDPAccessToken: idpAccessToken,
|
||||||
IDPIDToken: idpIDToken,
|
IDPRefreshToken: idpRefreshToken,
|
||||||
ExpiresAt: expiresAt,
|
IDPIDToken: idpIDToken,
|
||||||
|
ExpiresAt: expiresAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -129,8 +129,24 @@ message IDPInformation{
|
|||||||
}
|
}
|
||||||
|
|
||||||
message IDPOAuthAccessInformation{
|
message IDPOAuthAccessInformation{
|
||||||
string access_token = 1;
|
// The access token returned by the external identity provider.
|
||||||
optional string id_token = 2;
|
string access_token = 1[
|
||||||
|
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
|
||||||
|
description: "Access token returned by the external identity provider"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
// The ID token is only set when it is returned by the external identity provider.
|
||||||
|
optional string id_token = 2[
|
||||||
|
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
|
||||||
|
description: "ID token returned by the external identity provider. Only set if the external identity provider returns an ID token."
|
||||||
|
}
|
||||||
|
];
|
||||||
|
// The refresh token is only set when it is returned by the external identity provider.
|
||||||
|
optional string refresh_token = 3 [
|
||||||
|
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
|
||||||
|
description: "Refresh token returned by the external identity provider. Only set if the external identity provider returns a refresh token."
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
message IDPLDAPAccessInformation{
|
message IDPLDAPAccessInformation{
|
||||||
|
|||||||
@@ -129,8 +129,24 @@ message IDPInformation{
|
|||||||
}
|
}
|
||||||
|
|
||||||
message IDPOAuthAccessInformation{
|
message IDPOAuthAccessInformation{
|
||||||
string access_token = 1;
|
// The access token returned by the external identity provider.
|
||||||
optional string id_token = 2;
|
string access_token = 1[
|
||||||
|
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
|
||||||
|
description: "Access token returned by the external identity provider"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
// The ID token is only set when it is returned by the external identity provider.
|
||||||
|
optional string id_token = 2[
|
||||||
|
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
|
||||||
|
description: "ID token returned by the external identity provider. Only set if the external identity provider returns an ID token."
|
||||||
|
}
|
||||||
|
];
|
||||||
|
// The refresh token is only set when it is returned by the external identity provider.
|
||||||
|
optional string refresh_token = 3 [
|
||||||
|
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
|
||||||
|
description: "Refresh token returned by the external identity provider. Only set if the external identity provider returns a refresh token."
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
message IDPLDAPAccessInformation{
|
message IDPLDAPAccessInformation{
|
||||||
|
|||||||
Reference in New Issue
Block a user