Skip to content

Commit a1583b1

Browse files
Avoid KeyNotFoundException
Resolves #768.
1 parent 75f4d3e commit a1583b1

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/AspNet.Security.OAuth.Slack/SlackAuthenticationOptions.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,28 @@ public SlackAuthenticationOptions()
2525
TokenEndpoint = SlackAuthenticationDefaults.TokenEndpoint;
2626
UserInformationEndpoint = SlackAuthenticationDefaults.UserInformationEndpoint;
2727

28-
ClaimActions.MapCustomJson(ClaimTypes.NameIdentifier, user =>
29-
string.Concat(user.GetProperty("team").GetString("id"), "|", user.GetProperty("user").GetString("id")));
3028
ClaimActions.MapJsonSubKey(ClaimTypes.Name, "user", "name");
3129
ClaimActions.MapJsonSubKey(ClaimTypes.Email, "user", "email");
3230
ClaimActions.MapJsonSubKey(Claims.UserId, "user", "id");
3331
ClaimActions.MapJsonSubKey(Claims.TeamId, "team", "id");
3432
ClaimActions.MapJsonSubKey(Claims.TeamName, "team", "name");
33+
ClaimActions.MapCustomJson(ClaimTypes.NameIdentifier, (element) =>
34+
{
35+
string? teamId = null;
36+
string? userId = null;
37+
38+
if (element.TryGetProperty("team", out var team))
39+
{
40+
teamId = team.GetString("id");
41+
}
42+
43+
if (element.TryGetProperty("user", out var user))
44+
{
45+
userId = user.GetString("id");
46+
}
47+
48+
return $"{teamId}|{userId}";
49+
});
3550

3651
Scope.Add("identity.basic");
3752
}

0 commit comments

Comments
 (0)