Skip to content

Commit

Permalink
Proper support for users that are coming from Google (#2329)
Browse files Browse the repository at this point in the history
### What's done:
- prod configuration for Google
- as legacy Google does not have 'login', so we use email as a name and trim @gmail from it
  • Loading branch information
orchestr7 authored Jul 14, 2023
1 parent 5192772 commit f2dd42b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions api-gateway/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ spring:
# See https://docs.github.com/en/rest/users/users#get-the-authenticated-user
# for more details.
user-name-attribute: login
google:
user-name-attribute: email
registration:
google:
client-id: 943335421056-7ova0sgv6o4goapkripv8dk3ov4og6kc.apps.googleusercontent.com
Expand Down
2 changes: 2 additions & 0 deletions api-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ spring:
# value that will work with GitHub API, where GitHub provides username as "login" in the response
# https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
user-name-attribute: login
google:
user-name-attribute: email
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ class RegistrationView : AbstractView<RegistrationProps, RegistrationViewState>(
}
}

private fun saveUser() {
private fun saveUser(inputUpdated: String) {
val newUserInfo = props.userInfo?.copy(
name = state.fieldsMap[InputTypes.USER_NAME]?.trim() ?: props.userInfo!!.name,
name = inputUpdated,
oldName = props.userInfo!!.name,
isActive = true,
)
Expand Down Expand Up @@ -221,13 +221,16 @@ class RegistrationView : AbstractView<RegistrationProps, RegistrationViewState>(
"PARAMETER_NAME_IN_OUTER_LAMBDA",
)
private fun ChildrenBuilder.renderInputForm() {
// google does not provide us login, only e-mail, so need to trim everything after "@gmail"
val rawInput = state.fieldsMap[InputTypes.USER_NAME] ?: ""
val atIndex = rawInput.indexOf('@')
val inputUpdated = if (atIndex >= 0) rawInput.substring(0, atIndex) else rawInput
form {
val input = state.fieldsMap[InputTypes.USER_NAME] ?: ""
div {
inputTextFormRequired {
form = InputTypes.USER_NAME
textValue = input
validInput = input.isEmpty() || input.isValidName()
textValue = inputUpdated
validInput = inputUpdated.isEmpty() || inputUpdated.isValidName()
classes = ""
name = "User name"
conflictMessage = state.conflictErrorMessage
Expand All @@ -244,7 +247,7 @@ class RegistrationView : AbstractView<RegistrationProps, RegistrationViewState>(
className = ClassName("btn btn-info mt-4 mr-3")
+"Registration"
onClick = {
saveUser()
saveUser(inputUpdated)
}
}
state.conflictErrorMessage?.let {
Expand Down

0 comments on commit f2dd42b

Please sign in to comment.