-
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
40
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.
Open
Add Etsy OAuth provider #1126
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
58bb3ee
feat: add Etsy OAuth provider
DevTKSS 22129b6
docs(EtsyProvider): Add Provider usage guide with samples and specifi…
DevTKSS e291fb3
test: add tests for Etsy OAuth provider
DevTKSS ae0b1d6
chore: Compare and align to other existing Providers
DevTKSS 47bdf17
chore: update const string to static readonly string
DevTKSS b60d67d
test(EtsyProvider): Added unit tests for EtsyAuthenticationOptions an…
DevTKSS ff08b69
chore: updated and documented test data in `bundle.json`
DevTKSS 84aab36
chore: Rename Public to Personal Access Type, to match the Etsy Api n…
DevTKSS 49c8764
chore(EtsyAccessTypes): Remove commented member and test/-cases that …
DevTKSS 056ca64
chore(EtsyProvider): tfm version bump
DevTKSS 8a03cf3
chore: Add DetailedUserInfoClaimMappings and add xml docs
DevTKSS a37be50
chore(Etsy): align oauth scopes with the docs table
DevTKSS dc74ed2
chore(EtsyAuthenticationHandler): rename variables and formating appl…
DevTKSS 4da0bed
chore(EtsyPostConfigureOptions): add DetailedUserInfo Config via Post…
DevTKSS cb671c7
chore: Update xml docs and refactor to Property pattern with declarat…
DevTKSS d926422
chore(EtsyOptionsValidation): apply Review suggestions
DevTKSS 3274b0c
test(EtsyProvider): Update tests accordingly to review suggestions an…
DevTKSS 5020b47
chore: xml docs updates and update bundle.json with the placeholder v…
DevTKSS 5cf8e94
chore: implement Options fed DetailedUserInfoEndpoint and set fallbac…
DevTKSS b6778e3
chore: fix test builds
DevTKSS 77e5d3e
chore: set InlineData to magic string "urn:etsy:shop_id" because only…
DevTKSS 0e7c558
chore(EtsyTests): apply workaround into PostConfigure test
DevTKSS 99e2873
chore: create seperate named log methods
DevTKSS a499c03
docs(EtsyProvider): Add links to etsy provider docs and author, updat…
DevTKSS 8f0c011
chore: applying PR rewording suggestion
DevTKSS 6bb5ca6
chore: Resolve Merge Conflicts from sln to slnx migration
DevTKSS d6173cf
refactor: Add blank line in project file, remove unused usings and up…
DevTKSS c4a7323
chore: include user_id in Defaults Claims
DevTKSS b0b1b3f
chore: change DetailedUserInfoEndpoint to concatenated string instead…
DevTKSS 25b9a45
revert(EtsyPostConfigureOptions): apply DetailedUserInfo Config via P…
DevTKSS 868bce2
revert(EtsyTests): apply workaround into PostConfigure test
DevTKSS 690633b
chore: remove tests for validating empty or not containing shop_r Opt…
DevTKSS 74eaa4d
chore: add user_id claim mapping test case
DevTKSS 5b80a6b
docs(etsy): Refactor to minimal guide
DevTKSS 8bf2b2d
chore: remove image for docs and remove in slnx
DevTKSS e2cfde5
Merge branch 'aspnet-contrib:dev' into add-etsy-oauth-provider
DevTKSS e6b3cac
chore: fix typo
DevTKSS d7836a2
chore: applying PR rewording suggestion
DevTKSS 88252a1
docs(etsy): Update Headings and table columns to match existing provi…
DevTKSS 8676a4a
chore: Update xml docs and introduce default value for DetailedUserIn…
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.