Skip to content

Commit 6e24b58

Browse files
damienmoulardClement-Roque
authored andcommitted
return userId after login
1 parent a6c1baf commit 6e24b58

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Diff for: Zenergy/Zenergy/Controllers/AccountController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public async Task<IHttpActionResult> GetExternalLogin(string provider, string er
271271
ClaimsIdentity cookieIdentity = await user.GenerateUserIdentityAsync(UserManager,
272272
CookieAuthenticationDefaults.AuthenticationType);
273273

274-
AuthenticationProperties properties = ApplicationOAuthProvider.CreateProperties(user.UserName);
274+
AuthenticationProperties properties = ApplicationOAuthProvider.CreateProperties(null, user.UserName);
275275
Authentication.SignIn(properties, oAuthIdentity, cookieIdentity);
276276
}
277277
else

Diff for: Zenergy/Zenergy/Providers/ApplicationOAuthProvider.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwner
5151
identity.AddClaim(new Claim("mail", context.UserName));
5252
identity.AddClaim(new Claim("role", "user"));
5353
identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
54-
54+
//identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.userId.ToString()));
55+
identity.AddClaim(new Claim("UserId", user.userId.ToString()));
56+
5557
if (user.member != null)
5658
{
5759
identity.AddClaim(new Claim(ClaimTypes.Role, "Member"));
@@ -69,7 +71,7 @@ public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwner
6971
identity.AddClaim(new Claim(ClaimTypes.Role, "Admin"));
7072
}
7173

72-
AuthenticationProperties properties = CreateProperties(user.mail);
74+
AuthenticationProperties properties = CreateProperties(user.userId.ToString(), user.mail);
7375
AuthenticationTicket ticket = new AuthenticationTicket(identity, properties);
7476
context.Validated(ticket);
7577
//context.Request.Context.Authentication.SignIn(cookiesIdentity);
@@ -83,6 +85,8 @@ public override Task TokenEndpoint(OAuthTokenEndpointContext context)
8385
context.AdditionalResponseParameters.Add(property.Key, property.Value);
8486
}
8587

88+
context.AdditionalResponseParameters.Add("userID", context.Identity.GetUserId());
89+
8690
return Task.FromResult<object>(null);
8791
}
8892

@@ -112,10 +116,11 @@ public override Task ValidateClientRedirectUri(OAuthValidateClientRedirectUriCon
112116
return Task.FromResult<object>(null);
113117
}
114118

115-
public static AuthenticationProperties CreateProperties(string userName)
119+
public static AuthenticationProperties CreateProperties(string userId, string userName)
116120
{
117121
IDictionary<string, string> data = new Dictionary<string, string>
118122
{
123+
{ "userId", userId },
119124
{ "userName", userName }
120125
};
121126
return new AuthenticationProperties(data);

0 commit comments

Comments
 (0)