Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OIDC name for gitlab and authelia #746

Merged

Conversation

fflorent
Copy link
Collaborator

Context

  1. Nor Authelia (see OIDC use username instead of display name for Grists name field #739) or Gitlab do provide given_name or family_name attributes in userinfo
  2. Gitlab does not provide an end_session_endpoint, which led to an ugly error when disconnecting

Solutions

  1. I propose to use display_name or name as alternative attributes for the given_name + family_name pair;
  2. I propose to just redirect to the logout page directly, the user won't be logged out in the IdP;

app/server/lib/OIDCConfig.ts Outdated Show resolved Hide resolved
// display_name is provided by Authelia for example.
userInfo.display_name ||
// name is provided by Gitlab for example.
userInfo.name;
Copy link
Member

Choose a reason for hiding this comment

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

Would it be important to fall back to a string (and not, say, undefined)? If none of these options are available, one more reasonable fallback would be email.split("@", 1)[0].

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Isn't it already handled? If I don't provide any name, the left part of the email seem to be used. The magic seems to be operated here:

if (!user.name) {
// Set the user's name if our provider knows it. Otherwise use their username
// from email, for lack of something better. If we don't have a profile at this
// time, then leave the name blank in the hopes of learning it when the user logs in.
user.name = (profile && (profile.name || email.split('@')[0])) || '';
needUpdate = true;
}

@fflorent fflorent force-pushed the oidc-name-for-gitlab-and-authelia branch from b432af3 to 2f080d1 Compare November 15, 2023 17:18
@fflorent
Copy link
Collaborator Author

fflorent commented Nov 15, 2023

@dsagal Thanks for your review! I answered to your comments :)

I also changed a bit of strategy, I allow customizing the administrator the user properties to read in userInfo for both name and email. Some other product seem to offer this ability (Hedgedoc through CMD_OAUTH2_USER_PROFILE_DISPLAY_NAME_ATTR or Outline through OIDC_USERNAME_CLAIM)

app/server/lib/OIDCConfig.ts Outdated Show resolved Hide resolved
envVar: 'GRIST_OIDC_SP_PROFILE_NAME_ATTR',
});

this._emailPropertyKey = section.flag('emailPropertyKey').readString({
Copy link
Member

Choose a reason for hiding this comment

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

With defaultValue, you should be able to change to requireString, and the result would have type string (so you wouldn't need the ? in declaration, or ! in usage).


private _extractName(userInfo: UserinfoResponse): string|undefined {
if (this._namePropertyKey) {
return userInfo[ this._namePropertyKey ] as string|undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Same here: String(userInfo[this._namePropertyKey]) would be safer (in case the actual value happens to be of some other type).

Copy link
Collaborator Author

@fflorent fflorent Nov 16, 2023

Choose a reason for hiding this comment

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

I rather propose userInfo[ this._namePropertyKey as any ]?.toString() so if the value is undefined/null, it is correctly handled here:

if (!user.name) {
// Set the user's name if our provider knows it. Otherwise use their username
// from email, for lack of something better. If we don't have a profile at this
// time, then leave the name blank in the hopes of learning it when the user logs in.
user.name = (profile && (profile.name || email.split('@')[0])) || '';
needUpdate = true;
}

app/server/lib/OIDCConfig.ts Outdated Show resolved Hide resolved
@fflorent fflorent requested a review from dsagal November 16, 2023 09:46
@fflorent
Copy link
Collaborator Author

Thanks again for your review @dsagal, I have taken them into account!

Copy link
Member

@dsagal dsagal left a comment

Choose a reason for hiding this comment

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

Thanks! One more request please, the rest looks good.

app/server/lib/OIDCConfig.ts Outdated Show resolved Hide resolved
Copy link
Member

@dsagal dsagal left a comment

Choose a reason for hiding this comment

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

Thank you!

@dsagal
Copy link
Member

dsagal commented Nov 20, 2023

@fflorent , there seems to be a merge conflict because of your other change to OIDC. Could you rebase?

@fflorent fflorent force-pushed the oidc-name-for-gitlab-and-authelia branch from 49b4908 to f224d9f Compare November 21, 2023 06:23
@fflorent
Copy link
Collaborator Author

@dsagal @georgegevoian Done :)

@dsagal dsagal merged commit f8c6892 into gristlabs:main Nov 21, 2023
13 checks passed
@fflorent fflorent deleted the oidc-name-for-gitlab-and-authelia branch November 21, 2023 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants