diff --git a/Functions/Authentication.cs b/Functions/Authentication.cs index 95083dc..ee1e723 100644 --- a/Functions/Authentication.cs +++ b/Functions/Authentication.cs @@ -53,12 +53,12 @@ public async Task GithubSignin( Logger.Error(error); throw new Exception(error); } - req.Headers.TryGetValue("Referer", out var _backEnd); - string backEnd = _backEnd.ToString() ?? req.GetDisplayUrl(); + req.Headers.TryGetValue("Referer", out var _backend); + string backend = _backend.Count != 0 ? _backend.First() : req.GetDisplayUrl(); string idToken = await _githubService.GetIdTokenAsync( authorization_code: code, - redirectUri: AuthenticationService.GetRedirectUri(backEnd, "api/signin-github")); + redirectUri: AuthenticationService.GetRedirectUri(backend, "api/signin-github")); // Treat it as an implicit flow-style URL so that my front-end can easily handle it with packages (angular-oauth2-oidc). return new RedirectResult($"{_frontEndUri}/pages/login-redirect#state={HttpUtility.UrlEncode(state)}&access_token={idToken}&token_type=Bearer&expires_in=3599&scope=email%20profile&authuser=0&prompt=none"); diff --git a/Services/Authentication/GithubService.cs b/Services/Authentication/GithubService.cs index a1aed51..3b97940 100644 --- a/Services/Authentication/GithubService.cs +++ b/Services/Authentication/GithubService.cs @@ -62,7 +62,7 @@ public async Task GetUserInfoFromTokenAsync(string token) using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync()); var identity = new ClaimsIdentity("github"); - identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, payload.RootElement.GetProperty("id").GetString() ?? "", ClaimValueTypes.String)); + identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, payload.RootElement.GetProperty("id").GetInt32().ToString(), ClaimValueTypes.Integer32)); identity.AddClaim(new Claim(ClaimTypes.Name, payload.RootElement.GetProperty("login").GetString() ?? "", ClaimValueTypes.String)); identity.AddClaim(new Claim(ClaimTypes.GivenName, payload.RootElement.GetProperty("name").GetString()?.Split(' ', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? "", ClaimValueTypes.String)); identity.AddClaim(new Claim(ClaimTypes.Surname, payload.RootElement.GetProperty("name").GetString()?.Split(' ', StringSplitOptions.RemoveEmptyEntries).LastOrDefault() ?? "", ClaimValueTypes.String));