mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Handle duplicated usernames with oidc login
This commit is contained in:
parent
577f3f768d
commit
0d325f2c73
@ -184,9 +184,9 @@ namespace Kyoo.Authentication.Views
|
|||||||
client.DefaultRequestHeaders.Add("Authorization", $"Basic {auth}");
|
client.DefaultRequestHeaders.Add("Authorization", $"Basic {auth}");
|
||||||
|
|
||||||
HttpResponseMessage resp = await client.PostAsync(
|
HttpResponseMessage resp = await client.PostAsync(
|
||||||
_BuildUrl(
|
|
||||||
prov.TokenUrl,
|
prov.TokenUrl,
|
||||||
new()
|
new FormUrlEncodedContent(
|
||||||
|
new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
["code"] = code,
|
["code"] = code,
|
||||||
["client_id"] = prov.ClientId,
|
["client_id"] = prov.ClientId,
|
||||||
@ -195,11 +195,12 @@ namespace Kyoo.Authentication.Views
|
|||||||
$"{options.PublicUrl.TrimEnd('/')}/api/auth/logged/{provider}",
|
$"{options.PublicUrl.TrimEnd('/')}/api/auth/logged/{provider}",
|
||||||
["grant_type"] = "authorization_code",
|
["grant_type"] = "authorization_code",
|
||||||
}
|
}
|
||||||
),
|
)
|
||||||
null
|
|
||||||
);
|
);
|
||||||
if (!resp.IsSuccessStatusCode)
|
if (!resp.IsSuccessStatusCode)
|
||||||
return BadRequest("Invalid code or configuration.");
|
return BadRequest(
|
||||||
|
$"Invalid code or configuration. {resp.StatusCode}: {await resp.Content.ReadAsStringAsync()}"
|
||||||
|
);
|
||||||
JwtToken? token = await resp.Content.ReadFromJsonAsync<JwtToken>();
|
JwtToken? token = await resp.Content.ReadFromJsonAsync<JwtToken>();
|
||||||
if (token is null)
|
if (token is null)
|
||||||
return BadRequest("Could not retrive token.");
|
return BadRequest("Could not retrive token.");
|
||||||
@ -232,7 +233,18 @@ namespace Kyoo.Authentication.Views
|
|||||||
|
|
||||||
User? user = await users.GetByExternalId(provider, extToken.Id);
|
User? user = await users.GetByExternalId(provider, extToken.Id);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
user = await users.Create(newUser);
|
user = await users.Create(newUser);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return BadRequest(
|
||||||
|
"A user already exists with the same username. If this is you, login via username and then link your account."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
return new JwtToken(
|
return new JwtToken(
|
||||||
tokenController.CreateAccessToken(user, out TimeSpan expireIn),
|
tokenController.CreateAccessToken(user, out TimeSpan expireIn),
|
||||||
await tokenController.CreateRefreshToken(user),
|
await tokenController.CreateRefreshToken(user),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user