0
Fork 0
mirror of https://github.com/stonith404/pingvin-share.git synced 2025-01-29 01:28:59 -05:00

fix(oauth): provider username is ignored when signing up using OAuth (#511)

* 🐛 Bug Report: Provider username is ignored when signing up using OAuth
Fixes #505

Signed-off-by: Marvin A. Ruder <signed@mruder.dev>

* Implement fallback logic for username conflicts

* Reprioritize claims for OIDC provider username

Signed-off-by: Marvin A. Ruder <signed@mruder.dev>

---------

Signed-off-by: Marvin A. Ruder <signed@mruder.dev>
This commit is contained in:
Marvin A. Ruder 2024-07-01 10:34:31 +02:00 committed by GitHub
parent 2dac38560b
commit 31366d961f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 7 deletions

View file

@ -102,9 +102,9 @@ export class OAuthService {
} }
} }
private async getAvailableUsername(email: string) { private async getAvailableUsername(preferredUsername: string) {
// only remove + and - from email for now (maybe not enough) // only remove + and - from preferred username for now (maybe not enough)
let username = email.split("@")[0].replace(/[+-]/g, "").substring(0, 20); let username = preferredUsername.replace(/[+-]/g, "").substring(0, 20);
while (true) { while (true) {
const user = await this.prisma.user.findFirst({ const user = await this.prisma.user.findFirst({
where: { where: {
@ -153,7 +153,7 @@ export class OAuthService {
const result = await this.auth.signUp({ const result = await this.auth.signUp({
email: user.email, email: user.email,
username: await this.getAvailableUsername(user.email), username: await this.getAvailableUsername(user.providerUsername),
password: null, password: null,
}); });

View file

@ -125,9 +125,9 @@ export abstract class GenericOidcProvider implements OAuthProvider<OidcToken> {
const username = claim const username = claim
? idTokenData[claim] ? idTokenData[claim]
: idTokenData.name || : idTokenData.preferred_username ||
idTokenData.nickname || idTokenData.name ||
idTokenData.preferred_username; idTokenData.nickname;
if (!username) { if (!username) {
this.logger.error( this.logger.error(