Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Update username on re-login #1367

Merged
merged 11 commits into from
Jun 8, 2017

Conversation

sbose78
Copy link
Member

@sbose78 sbose78 commented Jun 5, 2017

fixes #1366
related to fabric8-ui/fabric8-ui#1442

  • tested on sso.prod-preview
  • updated username in kc.
  • re-logged in ( localhost )
  • new username showed up as required.

@sbose78 sbose78 changed the title Update username on re-login WIP Update username on re-login Jun 5, 2017
Copy link
Contributor

@alexeykazakov alexeykazakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM so far.

login/service.go Outdated
@@ -708,6 +709,15 @@ func (keycloak *KeycloakOAuthProvider) CreateOrUpdateKeycloakUser(accessToken st
}, "unable to update user")
return nil, nil, errors.New("Cant' update user " + err.Error())
}
err = keycloak.Identities.Save(ctx, identity)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a transaction to save both User and Identity.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done.

@codecov-io
Copy link

codecov-io commented Jun 5, 2017

Codecov Report

Merging #1367 into master will decrease coverage by 0.15%.
The diff coverage is 11.76%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1367      +/-   ##
==========================================
- Coverage   59.96%   59.81%   -0.16%     
==========================================
  Files         119      119              
  Lines       10872    10906      +34     
==========================================
+ Hits         6519     6523       +4     
- Misses       3714     3743      +29     
- Partials      639      640       +1
Impacted Files Coverage Δ
login/service.go 39.63% <11.76%> (-1.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24e228e...7e90748. Read the comment docs.

@sbose78 sbose78 changed the title WIP Update username on re-login Update username on re-login Jun 5, 2017
Copy link
Contributor

@alexeykazakov alexeykazakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM. Just one comment about checking if the user/identity has changed.

login/service.go Outdated
@@ -699,14 +700,33 @@ func (keycloak *KeycloakOAuthProvider) CreateOrUpdateKeycloakUser(accessToken st
}
// let's update the existing user with the fullname, email and avatar from Keycloak,
// in case the user changed them since the last time he/she logged in
fillUser(claims, user)
err = keycloak.Users.Save(ctx, user)
fillUser(claims, user, identity)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check if User or Identity actaully changed. If so then update them. If not then we can skip it:
fillUser(claims *keycloakTokenClaims, user *account.User, identity *account.Identity) (userChanged, identityChanged bool, error)

login/service.go Outdated
}, "unable to create user/identity")
return nil, nil, errors.New("Cant' create user/identity " + err.Error())
return nil, nil, errors.New("Cant' update user/identity from claims" + err.Error())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: error messages tend to avoid negation, you can use instead failed to, unable to, invalid ...

@sbose78
Copy link
Member Author

sbose78 commented Jun 7, 2017

[test]

@alexeykazakov
Copy link
Contributor

[test]

@sbose78 sbose78 merged commit 5c41f34 into fabric8-services:master Jun 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Username doesn't get updated from keycloak
4 participants