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:
parent
2dac38560b
commit
31366d961f
2 changed files with 7 additions and 7 deletions
|
@ -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,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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(
|
||||||
|
|
Loading…
Add table
Reference in a new issue