Skip to content

Commit

Permalink
Add sample code for avatar claim
Browse files Browse the repository at this point in the history
Add some sample code to the documentation showing how to map the user's avatar URL to a claim.
  • Loading branch information
martincostello committed Aug 25, 2021
1 parent faa1149 commit 9470bbe
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/discord.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,26 @@ _None._
| Property Name | Property Type | Description | Default Value |
|:--|:--|:--|:--|
| `Prompt` | `string?` | The value to use for the `prompt` query string parameter when making HTTP requests to the authorization endpoint. | `null` |

## Avatars as Claims

Versions of the Discord provider before version `6.0.0` would automatically map the user's avatar URL as the `urn:discord:avatar:url` claim.

This functionality is no longer built-in (see #584 and #585), but can be added to your application with some extra code similar to that shown in the sample below.

```csharp
services.AddAuthentication(options => /* Auth configuration */)
.AddDiscord(options =>
{
options.ClientId = "my-client-id";
options.ClientSecret = "my-client-secret";

options.ClaimActions.MapCustomJson("urn:discord:avatar:url", user =>
string.Format(
CultureInfo.InvariantCulture,
"https://cdn.discordapp.com/avatars/{0}/{1}.{2}",
user.GetString("id"),
user.GetString("avatar"),
user.GetString("avatar").StartsWith("a_") ? "gif" : "png"));
});
```

0 comments on commit 9470bbe

Please sign in to comment.