Skip to content

Commit

Permalink
finished merging oidc and oauth2 [#523]
Browse files Browse the repository at this point in the history
  • Loading branch information
roberlander2 committed Aug 24, 2022
1 parent 70acd64 commit fae60af
Show file tree
Hide file tree
Showing 6 changed files with 428 additions and 550 deletions.
8 changes: 4 additions & 4 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"filename": "core/auth/apis.go",
"hashed_secret": "4d55af37dbbb6a42088d917caa1ca25428ec42c9",
"is_verified": false,
"line_number": 1937
"line_number": 1939
}
],
"core/auth/auth.go": [
Expand Down Expand Up @@ -193,7 +193,7 @@
"filename": "core/auth/auth_type_oauth2.go",
"hashed_secret": "f8dabcd142517fb16418a3a2790f3da31392537a",
"is_verified": false,
"line_number": 130
"line_number": 122
}
],
"core/auth/auth_type_oidc.go": [
Expand All @@ -202,7 +202,7 @@
"filename": "core/auth/auth_type_oidc.go",
"hashed_secret": "f8dabcd142517fb16418a3a2790f3da31392537a",
"is_verified": false,
"line_number": 122
"line_number": 113
}
],
"driven/emailer/adapter.go": [
Expand Down Expand Up @@ -288,5 +288,5 @@
}
]
},
"generated_at": "2022-08-23T22:08:15Z"
"generated_at": "2022-08-24T20:24:53Z"
}
42 changes: 22 additions & 20 deletions core/auth/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (a *Auth) Refresh(refreshToken string, apiKey string, l *logs.Log) (*model.
permissions := []string{}

// - generate new params and update the account if needed(if external auth type)
var externalIDChanges map[string]string
// var externalIDChanges map[string]string
if loginSession.AuthType.IsExternal {
extAuthType, err := a.getExternalAuthTypeImpl(loginSession.AuthType)
if err != nil {
Expand All @@ -344,28 +344,30 @@ func (a *Auth) Refresh(refreshToken string, apiKey string, l *logs.Log) (*model.
return nil, errors.WrapErrorAction("error refreshing external auth type on refresh", "", nil, err)
}

//check if need to update the account data
authType, err := a.storage.FindAuthType(loginSession.AuthType.ID)
if err != nil || authType == nil {
l.Infof("error getting auth type - %s", refreshToken)
if err == nil {
err = errors.ErrorData(logutils.StatusMissing, model.TypeAuthType, &logutils.FieldArgs{"id": loginSession.AuthType.ID})
if externalUser != nil {
//check if need to update the account data
authType, err := a.storage.FindAuthType(loginSession.AuthType.ID)
if err != nil || authType == nil {
l.Infof("error getting auth type - %s", refreshToken)
if err == nil {
err = errors.ErrorData(logutils.StatusMissing, model.TypeAuthType, &logutils.FieldArgs{"id": loginSession.AuthType.ID})
}
return nil, errors.WrapErrorAction("error getting auth type", "", nil, err)
}
externalIDChanges, err := a.updateDataIfNeeded(*loginSession.AccountAuthType, *externalUser, *authType, loginSession.AppOrg, l)
if err != nil {
return nil, errors.WrapErrorAction("update account if needed on refresh", "", nil, err)
}
for k, v := range externalIDChanges {
if loginSession.ExternalIDs == nil {
loginSession.ExternalIDs = make(map[string]string)
}
loginSession.ExternalIDs[k] = v
}
return nil, errors.WrapErrorAction("error getting auth type", "", nil, err)
}
externalIDChanges, err = a.updateDataIfNeeded(*loginSession.AccountAuthType, *externalUser, *authType, loginSession.AppOrg, l)
if err != nil {
return nil, errors.WrapErrorAction("update account if needed on refresh", "", nil, err)
}

loginSession.Params = refreshedData //assign the refreshed data
}

for k, v := range externalIDChanges {
if loginSession.ExternalIDs == nil {
loginSession.ExternalIDs = make(map[string]string)
if refreshedData != nil {
loginSession.Params = refreshedData //assign the refreshed data
}
loginSession.ExternalIDs[k] = v
}

if !anonymous {
Expand Down

0 comments on commit fae60af

Please sign in to comment.