Skip to content

Commit 3f39b3b

Browse files
committed
chore: apply PR reword suggestions
1 parent 36cacb2 commit 3f39b3b

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

docs/etsy.md

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ Here is a comprehensive `appsettings.json` example covering supported options an
206206
"Etsy": {
207207
"ClientId": "your-etsy-api-key",
208208
"IncludeDetailedUserInfo": true,
209+
"DetailedUserInfoEndpoint": "https://openapi.etsy.com/v3/application/users/{0}",
210+
"AuthorizationEndpoint": "https://www.etsy.com/oauth/connect",
211+
"TokenEndpoint": "https://openapi.etsy.com/v3/public/oauth/token",
212+
"UserInformationEndpoint": "https://openapi.etsy.com/v3/application/users/me",
209213
"SaveTokens": true,
210214
"Scopes": [ "shops_r", "email_r" ]
211215
}
@@ -215,7 +219,9 @@ Here is a comprehensive `appsettings.json` example covering supported options an
215219
> [!NOTE]
216220
> We recommend saving tokens (`SaveTokens = true`) to facilitate token refresh, so the user does not need to re-authenticate frequently.
217221
> [!NOTE]
218-
> If you bind from appsettings, make sure to either set no scopes, if the basic `shops_r` scope is sufficient (`IncludeDetailedUserInfo` set to `true` would also add `email_r`), or always include them into the configuration. The handler does not automatically add it when binding from configuration.
222+
> If `IncludeDetailedUserInfo` is set to `true` and the scopes `shops_r` and `email_r` scopes are sufficient, you don't need to set additional scopes in `appsettings.json`, they are added automatically.
223+
> [!TIP]
224+
> We recommend using the `EtsyAuthenticationDefaults` class in your `.AddEtsy` call which contains the default endpoint URLs.
219225
220226
If you bind then from configuration, set the options in code, for example:
221227

@@ -228,21 +234,35 @@ builder.Services.AddAuthentication(options =>
228234
.AddCookie()
229235
.AddEtsy(options =>
230236
{
231-
var section = builder.Configuration.GetSection("Etsy").Get<EtsyAuthenticationOptions>();
232-
options.ClientId = section.ClientId!;
233-
options.IncludeDetailedUserInfo = section.IncludeDetailedUserInfo;
234-
options.SaveTokens = section.SaveTokens;
237+
var section = builder.Configuration.GetSection("Etsy");
238+
options.ClientId = section.GetValue<string?>("ClientId")
239+
?? throw new InvalidOperationException("Etsy:ClientId configuration value is missing.");
240+
241+
// For the Detailed User Info Endpoint and SaveTokens are default values pre-set, but you can override them here
242+
options.IncludeDetailedUserInfo = section.GetValue<bool>("IncludeDetailedUserInfo");
243+
options.SaveTokens = section.GetValue<bool>("SaveTokens");
244+
245+
// Use the defaults from EtsyAuthenticationDefaults, if you want to repeat them here, but they are set automatically
246+
options.AuthorizationEndpoint = EtsyAuthenticationDefaults.AuthorizationEndpoint;
247+
options.TokenEndpoint = EtsyAuthenticationDefaults.TokenEndpoint;
248+
options.UserInformationEndpoint = EtsyAuthenticationDefaults.UserInformationEndpoint;
235249

236250
// Apply scopes from config if present
237-
var scopes = section.GetSection("Scopes").Get<string[]?>();
251+
var scopes = section.Get<string[]>("Scopes");
238252

239-
foreach (var scope in scopes)
253+
if (scopes is not null)
240254
{
241-
options.Scope.Add(scope);
255+
foreach (var scope in scopes)
256+
{
257+
options.Scope.Add(scope);
258+
}
242259
}
243260

244-
// Optionally add image claim
245-
options.AddImageClaim();
261+
// Optionally Map the image claim
262+
options.ClaimActions.MapImageClaim();
263+
264+
// Map other Claims
265+
options.ClaimActions.MapJsonKey("urn:etsy:listingsWrite", "listings_w");
246266
})
247267
```
248268

src/AspNet.Security.OAuth.Etsy/ClaimActionCollectionExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99

1010
namespace Microsoft.Extensions.DependencyInjection;
1111

12+
/// <summary>
13+
/// Provides extension methods for <see cref="ClaimActionCollection"/> to map Etsy API specific user claims.
14+
/// </summary>
1215
public static class ClaimActionCollectionExtensions
1316
{
17+
/// <summary>
18+
/// Maps the Etsy user's profile image URL (75x75) to the <see cref="EtsyAuthenticationConstants.Claims.ImageUrl"/> claim.
19+
/// </summary>
1420
public static void MapImageClaim(this ClaimActionCollection collection)
1521
{
1622
collection.MapJsonKey(EtsyAuthenticationConstants.Claims.ImageUrl, "image_url_75x75");

0 commit comments

Comments
 (0)