-
Notifications
You must be signed in to change notification settings - Fork 550
Add Etsy OAuth provider #1126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DevTKSS
wants to merge
37
commits into
aspnet-contrib:dev
Choose a base branch
from
DevTKSS:add-etsy-oauth-provider
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+774
−0
Open
Add Etsy OAuth provider #1126
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
6149d74
feat: add Etsy OAuth provider
DevTKSS cbfe539
docs(EtsyProvider): Add Provider usage guide with samples and specifi…
DevTKSS f14ca12
test: add tests for Etsy OAuth provider
DevTKSS 7f57311
chore: Compare and align to other existing Providers
DevTKSS 72267d1
chore: update const string to static readonly string
DevTKSS 8492915
test(EtsyProvider): Added unit tests for EtsyAuthenticationOptions an…
DevTKSS 0c3861b
chore: updated and documented test data in `bundle.json`
DevTKSS df01a95
chore: Rename Public to Personal Access Type, to match the Etsy Api n…
DevTKSS 2b0e3ab
chore(EtsyAccessTypes): Remove commented member and test/-cases that …
DevTKSS 1269f31
chore(EtsyProvider): tfm version bump
DevTKSS ee9eba0
chore: Add DetailedUserInfoClaimMappings and add xml docs
DevTKSS 5374092
chore(Etsy): align oauth scopes with the docs table
DevTKSS 2a791c1
chore(EtsyAuthenticationHandler): rename variables and formating appl…
DevTKSS e350020
chore(EtsyPostConfigureOptions): add DetailedUserInfo Config via Post…
DevTKSS 0dc3821
chore: Update xml docs and refactor to Property pattern with declarat…
DevTKSS a272fde
chore(EtsyOptionsValidation): apply Review suggestions
DevTKSS 6a3fb4c
test(EtsyProvider): Update tests accordingly to review suggestions an…
DevTKSS 7eab685
chore: xml docs updates and update bundle.json with the placeholder v…
DevTKSS 9a8035e
chore: implement Options fed DetailedUserInfoEndpoint and set fallbac…
DevTKSS 293ad3a
chore: fix test builds
DevTKSS 523e8d8
chore: set InlineData to magic string "urn:etsy:shop_id" because only…
DevTKSS f9358a7
chore(EtsyTests): apply workaround into PostConfigure test
DevTKSS b9f8c39
chore: create seperate named log methods
DevTKSS 30c5534
docs(EtsyProvider): Add links to etsy provider docs and author, updat…
DevTKSS 646527c
chore: applying PR rewording suggestion
DevTKSS 967dee9
chore: Resolve Merge Conflicts from sln to slnx migration
DevTKSS fc30df3
refactor: Add blank line in project file, remove unused usings and up…
DevTKSS ffa225a
chore: include user_id in Defaults Claims
DevTKSS 7d98335
chore: change DetailedUserInfoEndpoint to concatenated string instead…
DevTKSS 19dfe9c
revert(EtsyPostConfigureOptions): apply DetailedUserInfo Config via P…
DevTKSS 8a97cf3
revert(EtsyTests): apply workaround into PostConfigure test
DevTKSS 131bc0d
chore: remove tests for validating empty or not containing shop_r Opt…
DevTKSS 69735f1
chore: add user_id claim mapping test case
DevTKSS cacf36d
docs(etsy): Refactor guide and update table column headers to align w…
DevTKSS ca39e8f
chore: Update xml docs and introduce default value for DetailedUserIn…
DevTKSS fd8dda9
chore: Make DetailedUserInfo not nullable and add Ending failsafe
DevTKSS aee5d4a
test: remove obsolete test as DetailedUserInfoEndpoint is now not lon…
DevTKSS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Integrating the Etsy Provider | ||
|
|
||
| Etsy's OAuth implementation uses Authorization Code with **PKCE** and issues **refresh tokens**. | ||
|
|
||
| This provider enables PKCE by default and validates scopes to match Etsy's requirements. | ||
|
|
||
| - [Integrating the Etsy Provider](#integrating-the-etsy-provider) | ||
| - [Example](#example) | ||
| - [Required Additional Settings](#required-additional-settings) | ||
| - [Optional Settings](#optional-settings) | ||
| - [Quick Links](#quick-links) | ||
|
|
||
| ## Example | ||
|
|
||
| ```csharp | ||
| using AspNet.Security.OAuth.Etsy; | ||
| using Microsoft.AspNetCore.Authentication; | ||
| using Microsoft.AspNetCore.Authentication.Cookies; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.Services | ||
| .AddAuthentication(options => { /* Authentication options */ }) | ||
| .AddEtsy(options => | ||
| { | ||
| options.ClientId = "my-etsy-client-id"; | ||
| options.ClientSecret = "my-etsy-client-secret"; // Optional as Etsy requires PKCE | ||
| options.IncludeDetailedUserInfo = true; // Optional to get first name, last name, email claims | ||
| options.ClaimActions.MapImageClaim(); // Optional Extension to map the image_url_75x75 claim, will not be mapped automatically | ||
| }); | ||
| ``` | ||
|
|
||
| ## Required Additional Settings | ||
|
|
||
| - You can obtain the Client ID (`keystring`) for your app by registering your application on [Etsy's developer portal](https://www.etsy.com/developers/your-apps). | ||
| - The ClientSecret (`shared secret` in the Etsy app details) is optional for public clients using PKCE. | ||
|
|
||
| ## Optional Settings | ||
|
|
||
| | Property Name | Property Type | Description | Default Value | | ||
| |:--|:--|:--|:--| | ||
| | `IncludeDetailedUserInfo` | `bool` | Fetch extended profile data with auto-mapped claims (Email, GivenName, Surname). | `false` | | ||
| | `ClaimActions.MapImageClaim()` | Extension method | Map the `image_url_75x75` claim to `EtsyAuthenticationConstants.Claims.ImageUrl`. | Not mapped automatically | | ||
| | `DetailedUserInfoEndpoint` | `string` | Endpoint to retrieve detailed user information. | `https://openapi.etsy.com/v3/application/users/` | | ||
|
|
||
| Additional helpers are available via `EtsyAuthenticationConstants.Scopes.*` for Etsy OAuth scopes and `EtsyAuthenticationConstants.Claims.*` for claim type constants used for the `getMe` and `getUser` endpoints. | ||
|
|
||
| ## Quick Links | ||
|
|
||
| | Resource | Link | | ||
| |:--|:--| | ||
| | Register your App on Etsy: | [Apps You've Made](https://www.etsy.com/developers/your-apps) | | ||
| | Official Etsy Authentication API Documentation: | [Etsy Developer Documentation](https://developers.etsy.com/documentation/essentials/authentication) | | ||
| | Requesting a Refresh OAuth Token: | [Etsy Refresh Token Guide](https://developers.etsy.com/documentation/essentials/authentication#requesting-a-refresh-oauth-token) | | ||
| | Etsy API Reference: | [Etsy API Reference](https://developers.etsy.com/documentation/reference) | |
21 changes: 21 additions & 0 deletions
21
src/AspNet.Security.OAuth.Etsy/AspNet.Security.OAuth.Etsy.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <PackageValidationBaselineVersion>10.1.0</PackageValidationBaselineVersion> | ||
| <TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks> | ||
DevTKSS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <!-- TODO Remove once published to NuGet.org --> | ||
| <DisablePackageBaselineValidation>true</DisablePackageBaselineValidation> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <Description>ASP.NET Core security middleware enabling Etsy authentication.</Description> | ||
| <Authors>Sonja Schweitzer</Authors> | ||
| <PackageTags>aspnetcore;authentication;etsy;oauth;security</PackageTags> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
| <PackageReference Include="JetBrains.Annotations" PrivateAssets="All" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
24 changes: 24 additions & 0 deletions
24
src/AspNet.Security.OAuth.Etsy/ClaimActionCollectionExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) | ||
| * See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers | ||
| * for more information concerning the license and the contributors participating to this project. | ||
| */ | ||
|
|
||
| using AspNet.Security.OAuth.Etsy; | ||
| using Microsoft.AspNetCore.Authentication.OAuth.Claims; | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| /// <summary> | ||
| /// Provides extension methods for <see cref="ClaimActionCollection"/> to map Etsy API specific user claims. | ||
| /// </summary> | ||
| public static class ClaimActionCollectionExtensions | ||
| { | ||
| /// <summary> | ||
| /// Maps the Etsy user's profile image URL (75x75) to the <see cref="EtsyAuthenticationConstants.Claims.ImageUrl"/> claim. | ||
| /// </summary> | ||
| public static void MapImageClaim(this ClaimActionCollection collection) | ||
| { | ||
DevTKSS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| collection.MapJsonKey(EtsyAuthenticationConstants.Claims.ImageUrl, "image_url_75x75"); | ||
DevTKSS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
94 changes: 94 additions & 0 deletions
94
src/AspNet.Security.OAuth.Etsy/EtsyAuthenticationConstants.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) | ||
| * See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers | ||
| * for more information concerning the license and the contributors participating to this project. | ||
| */ | ||
|
|
||
| namespace AspNet.Security.OAuth.Etsy; | ||
|
|
||
| /// <summary> | ||
| /// Contains constants specific to the <see cref="EtsyAuthenticationHandler"/>. | ||
| /// </summary> | ||
| public static class EtsyAuthenticationConstants | ||
| { | ||
| /// <summary> | ||
| /// Contains claim type constants specific to Etsy authentication. | ||
| /// </summary> | ||
| public static class Claims | ||
| { | ||
| /// <summary>The claim type for the user's Etsy user ID.</summary> | ||
| public static readonly string UserId = "urn:etsy:user_id"; | ||
|
|
||
| /// <summary>The claim type for the user's Etsy shop ID.</summary> | ||
| public static readonly string ShopId = "urn:etsy:shop_id"; | ||
|
|
||
| /// <summary>The claim type for the user's profile image URL.</summary> | ||
| public static readonly string ImageUrl = "urn:etsy:image_url"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Contains <see href="https://developers.etsy.com/documentation/reference#section/Authentication/oauth2">Etsy OAuth Scopes</see> constants for Etsy authentication. | ||
| /// </summary> | ||
| public static class Scopes | ||
| { | ||
| /// <summary>See billing and shipping addresses</summary> | ||
| public static readonly string AddressRead = "address_r"; | ||
|
|
||
| /// <summary>Update billing and shipping addresses</summary> | ||
| public static readonly string AddressWrite = "address_w"; | ||
|
|
||
| /// <summary>See all billing statement data</summary> | ||
| public static readonly string BillingRead = "billing_r"; | ||
|
|
||
| /// <summary>Read shopping carts</summary> | ||
| public static readonly string CartRead = "cart_r"; | ||
|
|
||
| /// <summary>Add/Remove from shopping carts</summary> | ||
| public static readonly string CartWrite = "cart_w"; | ||
|
|
||
| /// <summary>Read a user profile</summary> | ||
| public static readonly string EmailRead = "email_r"; | ||
|
|
||
| /// <summary>See private favorites</summary> | ||
| public static readonly string FavoritesRead = "favorites_r"; | ||
|
|
||
| /// <summary>Add/Remove favorites</summary> | ||
| public static readonly string FavoritesWrite = "favorites_w"; | ||
|
|
||
| /// <summary>See purchase info in feedback</summary> | ||
| public static readonly string FeedbackRead = "feedback_r"; | ||
|
|
||
| /// <summary>Delete listings</summary> | ||
| public static readonly string ListingsDelete = "listings_d"; | ||
|
|
||
| /// <summary>See all listings (including expired etc)</summary> | ||
| public static readonly string ListingsRead = "listings_r"; | ||
|
|
||
| /// <summary>Create/Edit listings</summary> | ||
| public static readonly string ListingsWrite = "listings_w"; | ||
|
|
||
| /// <summary>See all profile data</summary> | ||
| public static readonly string ProfileRead = "profile_r"; | ||
|
|
||
| /// <summary>Update user profile, avatar, etc</summary> | ||
| public static readonly string ProfileWrite = "profile_w"; | ||
|
|
||
| /// <summary>See recommended listings</summary> | ||
| public static readonly string RecommendRead = "recommend_r"; | ||
|
|
||
| /// <summary>Accept/Reject recommended listings</summary> | ||
| public static readonly string RecommendWrite = "recommend_w"; | ||
|
|
||
| /// <summary>See private shop info</summary> | ||
| public static readonly string ShopsRead = "shops_r"; | ||
|
|
||
| /// <summary>Update shop</summary> | ||
| public static readonly string ShopsWrite = "shops_w"; | ||
|
|
||
| /// <summary>See all checkout/payment data</summary> | ||
| public static readonly string TransactionsRead = "transactions_r"; | ||
|
|
||
| /// <summary>Update receipts</summary> | ||
| public static readonly string TransactionsWrite = "transactions_w"; | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
src/AspNet.Security.OAuth.Etsy/EtsyAuthenticationDefaults.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) | ||
| * See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers | ||
| * for more information concerning the license and the contributors participating to this project. | ||
| */ | ||
|
|
||
| namespace AspNet.Security.OAuth.Etsy; | ||
|
|
||
| /// <summary> | ||
| /// Default values used by the Etsy authentication middleware. | ||
| /// </summary> | ||
| public static class EtsyAuthenticationDefaults | ||
| { | ||
| /// <summary> | ||
| /// Default value for <see cref="AuthenticationScheme.Name"/>. | ||
| /// </summary> | ||
| public const string AuthenticationScheme = "Etsy"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="AuthenticationScheme.DisplayName"/>. | ||
| /// </summary> | ||
| public static readonly string DisplayName = "Etsy"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="AuthenticationSchemeOptions.ClaimsIssuer"/>. | ||
| /// </summary> | ||
| public static readonly string Issuer = "Etsy"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="RemoteAuthenticationOptions.CallbackPath"/>. | ||
| /// </summary> | ||
| public static readonly string CallbackPath = "/signin-etsy"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="OAuthOptions.AuthorizationEndpoint"/>. | ||
| /// </summary> | ||
| public static readonly string AuthorizationEndpoint = "https://www.etsy.com/oauth/connect"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="OAuthOptions.TokenEndpoint"/>. | ||
| /// </summary> | ||
| public static readonly string TokenEndpoint = "https://openapi.etsy.com/v3/public/oauth/token"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/> <see href="https://developers.etsy.com/documentation/reference/#operation/getMe">Etsy getMe Endpoint</see>. | ||
| /// </summary> | ||
| public static readonly string UserInformationEndpoint = "https://openapi.etsy.com/v3/application/users/me"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for receiving the user profile based upon a unique user ID <see href="https://developers.etsy.com/documentation/reference/#operation/getUser">getUser</see>. | ||
| /// </summary> | ||
| public static readonly string DetailedUserInfoEndpoint = "https://openapi.etsy.com/v3/application/users/"; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.