-
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
base: dev
Are you sure you want to change the base?
Add Etsy OAuth provider #1126
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new Etsy OAuth 2.0 authentication provider to the AspNet.Security.OAuth.Providers library. The implementation supports Etsy's Authorization Code flow with PKCE, personal access type (public client), and optional detailed user information fetching.
- Implements complete OAuth 2.0 flow with PKCE requirement
- Supports optional detailed user profile enrichment via configurable flag
- Includes comprehensive validation for required scopes and configuration
Reviewed Changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/AspNet.Security.OAuth.Etsy/EtsyAuthenticationOptions.cs |
Configuration options with validation logic for Etsy OAuth requirements |
src/AspNet.Security.OAuth.Etsy/EtsyAuthenticationHandler.cs |
OAuth handler implementing token exchange and user info retrieval |
src/AspNet.Security.OAuth.Etsy/EtsyAuthenticationExtensions.cs |
Extension methods for registering Etsy authentication |
src/AspNet.Security.OAuth.Etsy/EtsyAuthenticationDefaults.cs |
Default endpoint URLs and configuration values |
src/AspNet.Security.OAuth.Etsy/EtsyAuthenticationConstants.cs |
Claim types and scope constants |
src/AspNet.Security.OAuth.Etsy/EtsyAuthenticationAccessType.cs |
Enum defining access types (Personal) |
test/AspNet.Security.OAuth.Providers.Tests/Etsy/EtsyTests.cs |
Integration tests for authentication flow and claims |
test/AspNet.Security.OAuth.Providers.Tests/Etsy/EtsyAuthenticationOptionsTests.cs |
Unit tests for options validation |
test/AspNet.Security.OAuth.Providers.Tests/Etsy/bundle.json |
Test fixture data for HTTP interception |
docs/etsy.md |
Comprehensive usage documentation with examples |
AspNet.Security.OAuth.Providers.sln |
Solution file updated with new project references |
Comments suppressed due to low confidence (2)
src/AspNet.Security.OAuth.Etsy/EtsyAuthenticationHandler.cs:51
- This assignment to userId is useless, since its value is never read.
var userId = meRoot.GetProperty("user_id").GetInt64();
src/AspNet.Security.OAuth.Etsy/EtsyAuthenticationHandler.cs:52
- This assignment to shopId is useless, since its value is never read.
var shopId = meRoot.GetProperty("shop_id").GetInt64();
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/AspNet.Security.OAuth.Etsy/AspNet.Security.OAuth.Etsy.csproj
Outdated
Show resolved
Hide resolved
test/AspNet.Security.OAuth.Providers.Tests/Etsy/EtsyAuthenticationOptionsTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 16 out of 17 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ad60b5b to
36cacb2
Compare
|
Thanks for responding to the various comments - I'll take a look at this again when I get the time. Shipping the release for .NET 10 was the main priority this week. |
|
@martincostello thanks for your response and time! I am not sure in this, because I have had lots of trouble with implementing oAuth in there, because of Antiforgery and Cors 😓 the Official MS Docs for oAuth2 are horribly lacking on guidiance when there is no exiting provider like Google or something OIDC that supports discovery endpoint, which the Etsy API doesn't have 👀 We do have the Auth Code Exchange implemented here, which is against the Cross Origin Forgery Attacking 🤔 And in the Authentication/Authorization docs for minimal api here:
Its not told in our Readme files, if we do need Cookie to be added, or if the oAuth Base Extension our Providers here are building on do this already for us by default. In case we need the dev user (like me then) to add this for e.g. have something like the Refreshing of the Token implemented (which I seen in none of the existing Providers here (?), so did not add it in the Etsy Provider too) eventually it would be usefull to add a Link to the Cookie Auth ms docs eventually to the OIDC docs which contains a auth flow diagram with BUT while on the social login providers docs do link to the External Providers Page, which also links to this repo (thats how I found it 😉) this would be missing information about Refreshing Tokens too 🤷 If you would like me to open another issue / PR for this to improve these spots, let me know 👍 |
|
You should be able to use our MVC sample App to test the changes locally. |
|
@martincostello Hey, I am on trying the provider with the [HttpPost("~/signin")]
public async Task<IActionResult> SignIn([FromForm] string provider)
{
// Note: the "provider" parameter corresponds to the external
// authentication provider chosen by the user agent.
if (string.IsNullOrWhiteSpace(provider))
{
return BadRequest();
}
if (!await HttpContext.IsProviderSupportedAsync(provider))
{
return BadRequest();
}
// Instruct the middleware corresponding to the requested external identity
// provider to redirect the user agent to its own authorization endpoint.
// Note: the authenticationScheme parameter must match the value configured in Startup.cs
return Challenge(new AuthenticationProperties { RedirectUri = "/" }, provider);
}Could you maybe take a quick look and let me know if I just misunderstood this and the CallbackPath set in Options can be used as expected?
the Value I would like to set is e.g. |
|
|
|
@martincostello 🎉 🥳 Worked!!! just that the |
martincostello
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't fully reviewed this PR yet, or thought about responding to the specific questions yet, but I've done a quick pass. I'll come back to this another time next week.
src/AspNet.Security.OAuth.Etsy/AspNet.Security.OAuth.Etsy.csproj
Outdated
Show resolved
Hide resolved
|
Please resolve merge conflicts - the |
- Added `EtsyAuthenticationDefaults` default value fields like `EtsyBaseUri` and `UserDetailsPath` - Added xml docs onto all `EtsyAuthenticationDefaults` fields - Added `EtsyAuthenticationOptions.IncludeDetailedUserInfo` Property - removed `EtsyPostConfigureOptions` as Etsy does not have dynamic endpoints or domain like GitHub - integrated validation logik into `EtsyAuthenticationOptions.Validate` override, like used for issue 610 fix
…d IncludeDetailedUserInfo Handler
…aming for the app Access level chore: applying PR rewording suggestion Co-authored-by: Martin Costello <martin@martincostello.com> chore: remove comments Co-authored-by: Martin Costello <martin@martincostello.com>
…are not needed chore(EtsyAccessType): Remove AccessType
Co-authored-by: Martin Costello <martin@martincostello.com>
there is no endpoint this could get from and as its in the table format in etsy api, it gets also not inserted into the api spec .json for CLI tools like Kiota
…y CA1863 suggestions, apply xml docs changes
…Configuration and add Extension for simpler ImageUriClaim
…k to defaults in handler
- openapi instead of just api - reverted formated string in bundle.json
… const strings could be used in attributes, not static readonly strings
User side Post configure is later than provider side post configure. this causes the Scope not to be evaluated and the Mappings are not applyed automatically HACK: add them all manually for the test postConfigure until decision is made this could be put in validate override or always consumer side?
TODO: Should be checked, we still need the full methods when using the attribute LoggerMessage. Maybe we can delete the non attribute using method then?
…e docs docs(PostConfigure): Add Warning that he needs to add the claims himself for detailed user info if he wants to use `PostConfigure` himself, which runs after the Provider side chore: apply PR reword suggestions chore: Update Etsy.md TOC chore: Apply PR suggestions
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1fcdc17 to
b855e84
Compare
|
@martincostello Resolved Merge Conflicts + cleaned commits up a bit |
src/AspNet.Security.OAuth.Etsy/AspNet.Security.OAuth.Etsy.csproj
Outdated
Show resolved
Hide resolved
… of CompositeFormat
…ostConfiguration and validate with tests
9550b58 to
5b80a6b
Compare
| // Extract user_id from the /me response required to get detailed user info. shop_id is mapped later via ClaimActions | ||
| var userId = meRoot.GetProperty("user_id").GetInt64(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this only needs to be done if Options.IncludeDetailedUserInfo is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martincostello yes it is, but if we need to run the ClaimActions in Line 64 before the conditional (could you check if we need to?) I would not exactly know how to do this, except from you want me to make another if statement for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I don't follow - the value is read and stored into a local variable and only used within that block, so if it isn't entered it's a redundant read.
Are you saying that if it wasn't read here but later that would cause a bug? If so, then that makes it seem like there's "magic" happening, which is itself a problem if the way the provider function isn't immediately clear from inspecting the code in the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅 no it isn't doing magic from what I understood from the mappings. The userId is used in the detailedUserInfo block some lines below, to fetch this if requested. 🤔
You remember the /users/{user_id}? This is what we need it for in the additional User details.
But it is possible that there is outdated code and the checks for the ClaimActions Types below is missing the userId which we do duplicate store in nameIdentity + Constant Map to urn:Etsy:user_id what I don't know is, if the RunClaimActions here before this is needed 🤔 if not than we might be able to only ask for the userId value once inside of the if statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅 no it isn't doing magic from what I understood from the mappings. The userId is used in the detailedUserInfo block some lines below, to fetch this if requested. 🤔
You remember the /users/{user_id}? This is what we need it for in the additional User details.
But it is possible that there is outdated code and the checks for the ClaimActions Types below is missing the userId which we do duplicate store in nameIdentity + Constant Map to urn:Etsy:user_id what I don't know is, if the RunClaimActions here before this is needed 🤔 if not than we might be able to only ask for the userId value once inside of the if statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm still not following your reply here.
The local variable userId is only used on line 69, which is after an if. Therefore the declaration and assignment of the variable can be moved from here to line 68.
if (Options.IncludeDetailedUserInfo)
{
var userId = meRoot.GetProperty("user_id").GetInt64();
using var detailedPayload = await GetDetailedUserInfoAsync(tokens, userId);
}| /// <returns>A <see cref="JsonDocument"/> containing the detailed user information.</returns> | ||
| protected virtual async Task<JsonDocument> GetDetailedUserInfoAsync([NotNull] OAuthTokenResponse tokens, long userId) | ||
| { | ||
| var userDetailsUrl = $"{Options.DetailedUserInfoEndpoint}{userId}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels prudent to handle if DetailedUserInfoEndpoint doesn't end in a / here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martincostello not sure what you mean by "prudent" sorry 😅 do you mean that we need to add a validation like .EndsWith('/') or what do you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If DetailedUserInfoEndpoint was overridden and the user forgot to add the trailing /, then the URL would be malformed.
| /// <remarks> | ||
| /// The placeholder for <c>user_id</c> needs to be <c>"{0}"</c> and will be replaced with the authenticated user's ID. | ||
| /// </remarks> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is outdated.
Co-authored-by: Martin Costello <martin@martincostello.com>
Co-authored-by: Martin Costello <martin@martincostello.com>
…ders layout and remove inherited settings

This pull request adds initial support for Etsy OAuth authentication to the codebase. It introduces the core implementation for an ASP.NET Core authentication provider, including configuration, constants, and documentation. The changes provide all the necessary building blocks and guidance for integrating Etsy login into an ASP.NET Core application.
Etsy OAuth Provider Implementation
AspNet.Security.OAuth.Etsy.csprojto define the package and its dependencies for the Etsy authentication provider.EtsyAuthenticationAccessTypeenum to distinguish between personal and commercial access types for Etsy apps.EtsyAuthenticationConstantsclass with claim and scope constants for mapping Etsy user data and permissions.EtsyAuthenticationDefaultswith all the required default values for endpoints, scheme names, and callback paths used by the Etsy authentication middleware.EtsyAuthenticationExtensionsto make it easy to add Etsy authentication to an ASP.NET Core application via the authentication builder.Documentation
docs/etsy.md, detailing configuration, required/optional settings, claims mapping, and sample code for integrating Etsy OAuth authentication.Note
The AccessType enum does so far only have one member
Personalbecause I only have this level of App registration and can not see or tell if the commercial Access Apps do somehow support confidential clients against the guidelines of the Etsy Authentication API. I asked their support some while ago which did tell that theshared secretwould be used at refresh, but there is no note at all for this in their docs, so this provider is adhering to the existing docs and oAuth standards RFC 6749 and does treat it as Public Client.Recognizing the #610 Issue in the past, I directly implemented the same fix up from the start, because even if the user sets the value, we don't have to require it, so the provider should also not fail because of not setting this.
Closes: #1082