Skip to content

Commit

Permalink
Avoid KeyNotFoundException
Browse files Browse the repository at this point in the history
Resolves #768.
  • Loading branch information
martincostello committed Sep 14, 2024
1 parent 75f4d3e commit a1583b1
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/AspNet.Security.OAuth.Slack/SlackAuthenticationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,28 @@ public SlackAuthenticationOptions()
TokenEndpoint = SlackAuthenticationDefaults.TokenEndpoint;
UserInformationEndpoint = SlackAuthenticationDefaults.UserInformationEndpoint;

ClaimActions.MapCustomJson(ClaimTypes.NameIdentifier, user =>
string.Concat(user.GetProperty("team").GetString("id"), "|", user.GetProperty("user").GetString("id")));
ClaimActions.MapJsonSubKey(ClaimTypes.Name, "user", "name");
ClaimActions.MapJsonSubKey(ClaimTypes.Email, "user", "email");
ClaimActions.MapJsonSubKey(Claims.UserId, "user", "id");
ClaimActions.MapJsonSubKey(Claims.TeamId, "team", "id");
ClaimActions.MapJsonSubKey(Claims.TeamName, "team", "name");
ClaimActions.MapCustomJson(ClaimTypes.NameIdentifier, (element) =>
{
string? teamId = null;
string? userId = null;
if (element.TryGetProperty("team", out var team))
{
teamId = team.GetString("id");
}
if (element.TryGetProperty("user", out var user))
{
userId = user.GetString("id");
}
return $"{teamId}|{userId}";
});

Scope.Add("identity.basic");
}
Expand Down

0 comments on commit a1583b1

Please sign in to comment.