-
Notifications
You must be signed in to change notification settings - Fork 551
Added "Meetup.com" provider #220
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2feeb48
First working version of Meetup provider
dance2die c3ee580
Removed commented-out code and an unused using reference
dance2die a3447be
Mapped all user's claim options
dance2die 7037b3c
Added Meetup provider to the solution
dance2die 42e771c
Updated indentation as suggested by "kinosang" on https://github.com/…
dance2die 522fb33
Fixed indentation as suggested by kinosang on #220
dance2die 8648b81
Introduced a ClaimType static constant class "MeetupClaimTypes" as su…
dance2die f15cb87
Updated Meetup package author & company in the package (I have forgot…
dance2die 1d66b8f
Migrate to the latest KoreBuild version
kevinchalet cb903be
First working version of Meetup provider
dance2die eef1c57
Removed commented-out code and an unused using reference
dance2die e8a00a2
Mapped all user's claim options
dance2die 4d32726
Added Meetup provider to the solution
dance2die f3a1c26
Updated indentation as suggested by "kinosang" on https://github.com/…
dance2die 8f6c909
Fixed indentation as suggested by kinosang on #220
dance2die 79d08a8
Introduced a ClaimType static constant class "MeetupClaimTypes" as su…
dance2die 7fe7f1b
Updated Meetup package author & company in the package (I have forgot…
dance2die ddf0259
Took remote solution
dance2die 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
First working version of Meetup provider
- Loading branch information
commit cb903bef0d4c4bed8e1d78467401d40ec4d1ce8e
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/AspNet.Security.OAuth.Meetup/AspNet.Security.OAuth.Meetup.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,20 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Import Project="..\..\build\packages.props" /> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <Description>ASP.NET Core security middleware enabling Meetup authentication.</Description> | ||
| <Authors>Kévin Chalet;Jerrie Pelser</Authors> | ||
| <PackageTags>aspnetcore;authentication;Meetup;oauth;security</PackageTags> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="JetBrains.Annotations" Version="$(JetBrainsVersion)" PrivateAssets="All" /> | ||
| <PackageReference Include="Microsoft.AspNetCore.Authentication.OAuth" Version="$(AspNetCoreVersion)" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
52 changes: 52 additions & 0 deletions
52
src/AspNet.Security.OAuth.Meetup/MeetupAuthenticationDefaults.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,52 @@ | ||
| /* | ||
| * 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 Microsoft.AspNetCore.Authentication; | ||
| using Microsoft.AspNetCore.Authentication.OAuth; | ||
|
|
||
| namespace AspNet.Security.OAuth.Meetup | ||
| { | ||
| /// <summary> | ||
| /// Default values used by the Meetup authentication middleware. | ||
| /// </summary> | ||
| public static class MeetupAuthenticationDefaults | ||
| { | ||
| /// <summary> | ||
| /// Default value for <see cref="AuthenticationScheme.Name"/>. | ||
| /// </summary> | ||
| public const string AuthenticationScheme = "Meetup"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="AuthenticationScheme.DisplayName"/>. | ||
| /// </summary> | ||
| public const string DisplayName = "Meetup"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="AuthenticationSchemeOptions.ClaimsIssuer"/>. | ||
| /// </summary> | ||
| public const string Issuer = "Meetup"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="RemoteAuthenticationOptions.CallbackPath"/>. | ||
| /// </summary> | ||
| public const string CallbackPath = "/signin-meetup"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="OAuthOptions.AuthorizationEndpoint"/>. | ||
| /// </summary> | ||
| public const string AuthorizationEndpoint = "https://secure.meetup.com/oauth2/authorize"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="OAuthOptions.TokenEndpoint"/>. | ||
| /// </summary> | ||
| public const string TokenEndpoint = "https://secure.meetup.com/oauth2/access"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>. | ||
| /// </summary> | ||
| public const string UserInformationEndpoint = "https://api.meetup.com/members/self"; | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
src/AspNet.Security.OAuth.Meetup/MeetupAuthenticationExtensions.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,76 @@ | ||
| /* | ||
| * 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 System; | ||
| using AspNet.Security.OAuth.Meetup; | ||
| using JetBrains.Annotations; | ||
| using Microsoft.AspNetCore.Authentication; | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection | ||
| { | ||
| /// <summary> | ||
| /// Extension methods to add Meetup authentication capabilities to an HTTP application pipeline. | ||
| /// </summary> | ||
| public static class MeetupAuthenticationExtensions | ||
| { | ||
| /// <summary> | ||
| /// Adds <see cref="MeetupAuthenticationHandler"/> to the specified | ||
| /// <see cref="AuthenticationBuilder"/>, which enables Meetup authentication capabilities. | ||
| /// </summary> | ||
| /// <param name="builder">The authentication builder.</param> | ||
| /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> | ||
| public static AuthenticationBuilder AddMeetup([NotNull] this AuthenticationBuilder builder) | ||
| { | ||
| return builder.AddMeetup(MeetupAuthenticationDefaults.AuthenticationScheme, options => { }); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds <see cref="MeetupAuthenticationHandler"/> to the specified | ||
| /// <see cref="AuthenticationBuilder"/>, which enables Meetup authentication capabilities. | ||
| /// </summary> | ||
| /// <param name="builder">The authentication builder.</param> | ||
| /// <param name="configuration">The delegate used to configure the OpenID 2.0 options.</param> | ||
| /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> | ||
| public static AuthenticationBuilder AddMeetup( | ||
| [NotNull] this AuthenticationBuilder builder, | ||
| [NotNull] Action<MeetupAuthenticationOptions> configuration) | ||
| { | ||
| return builder.AddMeetup(MeetupAuthenticationDefaults.AuthenticationScheme, configuration); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds <see cref="MeetupAuthenticationHandler"/> to the specified | ||
| /// <see cref="AuthenticationBuilder"/>, which enables Meetup authentication capabilities. | ||
| /// </summary> | ||
| /// <param name="builder">The authentication builder.</param> | ||
| /// <param name="scheme">The authentication scheme associated with this instance.</param> | ||
| /// <param name="configuration">The delegate used to configure the Meetup options.</param> | ||
| /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> | ||
| public static AuthenticationBuilder AddMeetup( | ||
| [NotNull] this AuthenticationBuilder builder, [NotNull] string scheme, | ||
| [NotNull] Action<MeetupAuthenticationOptions> configuration) | ||
| { | ||
| return builder.AddMeetup(scheme, MeetupAuthenticationDefaults.DisplayName, configuration); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds <see cref="MeetupAuthenticationHandler"/> to the specified | ||
| /// <see cref="AuthenticationBuilder"/>, which enables Meetup authentication capabilities. | ||
| /// </summary> | ||
| /// <param name="builder">The authentication builder.</param> | ||
| /// <param name="scheme">The authentication scheme associated with this instance.</param> | ||
| /// <param name="caption">The optional display name associated with this instance.</param> | ||
| /// <param name="configuration">The delegate used to configure the Meetup options.</param> | ||
| /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> | ||
| public static AuthenticationBuilder AddMeetup( | ||
| [NotNull] this AuthenticationBuilder builder, | ||
| [NotNull] string scheme, [CanBeNull] string caption, | ||
| [NotNull] Action<MeetupAuthenticationOptions> configuration) | ||
| { | ||
| return builder.AddOAuth<MeetupAuthenticationOptions, MeetupAuthenticationHandler>(scheme, caption, configuration); | ||
| } | ||
| } | ||
| } |
75 changes: 75 additions & 0 deletions
75
src/AspNet.Security.OAuth.Meetup/MeetupAuthenticationHandler.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,75 @@ | ||
| /* | ||
| * 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 System.Linq; | ||
| using System.Net.Http; | ||
| using System.Net.Http.Headers; | ||
| using System.Security.Claims; | ||
| using System.Text.Encodings.Web; | ||
| using System.Threading.Tasks; | ||
| using JetBrains.Annotations; | ||
| using Microsoft.AspNetCore.Authentication; | ||
| using Microsoft.AspNetCore.Authentication.OAuth; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Extensions.Options; | ||
| using Newtonsoft.Json.Linq; | ||
|
|
||
| namespace AspNet.Security.OAuth.Meetup | ||
| { | ||
| public class MeetupAuthenticationHandler : OAuthHandler<MeetupAuthenticationOptions> | ||
| { | ||
| public MeetupAuthenticationHandler( | ||
| [NotNull] IOptionsMonitor<MeetupAuthenticationOptions> options, | ||
| [NotNull] ILoggerFactory logger, | ||
| [NotNull] UrlEncoder encoder, | ||
| [NotNull] ISystemClock clock) | ||
| : base(options, logger, encoder, clock) | ||
| { | ||
| } | ||
|
|
||
| protected override async Task<AuthenticationTicket> CreateTicketAsync([NotNull] ClaimsIdentity identity, | ||
| [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) | ||
| { | ||
| var request = new HttpRequestMessage(HttpMethod.Get, Options.UserInformationEndpoint); | ||
| request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
| request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken); | ||
|
|
||
| var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted); | ||
| if (!response.IsSuccessStatusCode) | ||
| { | ||
| Logger.LogError("An error occurred while retrieving the user profile: the remote server " + | ||
| "returned a {Status} response with the following payload: {Headers} {Body}.", | ||
| /* Status: */ response.StatusCode, | ||
| /* Headers: */ response.Headers.ToString(), | ||
| /* Body: */ await response.Content.ReadAsStringAsync()); | ||
|
|
||
| throw new HttpRequestException("An error occurred while retrieving the user profile."); | ||
| } | ||
|
|
||
| var payload = JObject.Parse(await response.Content.ReadAsStringAsync()); | ||
|
|
||
| var principal = new ClaimsPrincipal(identity); | ||
| var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload); | ||
| context.RunClaimActions(payload); | ||
|
|
||
| //// When the email address is not public, retrieve it from | ||
| //// the emails endpoint if the user:email scope is specified. | ||
| //if (!string.IsNullOrEmpty(Options.UserEmailsEndpoint) && | ||
| // !identity.HasClaim(claim => claim.Type == ClaimTypes.Email) && Options.Scope.Contains("user:email")) | ||
| //{ | ||
| // var address = await GetEmailAsync(tokens); | ||
| // if (!string.IsNullOrEmpty(address)) | ||
| // { | ||
| // identity.AddClaim(new Claim(ClaimTypes.Email, address, ClaimValueTypes.String, Options.ClaimsIssuer)); | ||
| // } | ||
| //} | ||
|
|
||
| await Options.Events.CreatingTicket(context); | ||
|
|
||
| return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name); | ||
| } | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
src/AspNet.Security.OAuth.Meetup/MeetupAuthenticationOptions.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,36 @@ | ||
| /* | ||
| * 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 System.Security.Claims; | ||
| using Microsoft.AspNetCore.Authentication; | ||
| using Microsoft.AspNetCore.Authentication.OAuth; | ||
| using Microsoft.AspNetCore.Http; | ||
|
|
||
| namespace AspNet.Security.OAuth.Meetup | ||
| { | ||
| /// <summary> | ||
| /// Defines a set of options used by <see cref="MeetupAuthenticationHandler"/>. | ||
| /// </summary> | ||
| public class MeetupAuthenticationOptions : OAuthOptions | ||
| { | ||
| public MeetupAuthenticationOptions() | ||
| { | ||
| ClaimsIssuer = MeetupAuthenticationDefaults.Issuer; | ||
|
|
||
| CallbackPath = new PathString(MeetupAuthenticationDefaults.CallbackPath); | ||
|
|
||
| AuthorizationEndpoint = MeetupAuthenticationDefaults.AuthorizationEndpoint; | ||
| TokenEndpoint = MeetupAuthenticationDefaults.TokenEndpoint; | ||
| UserInformationEndpoint = MeetupAuthenticationDefaults.UserInformationEndpoint; | ||
|
|
||
| ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id"); | ||
| ClaimActions.MapJsonKey(ClaimTypes.Name, "login"); | ||
| ClaimActions.MapJsonKey(ClaimTypes.Email, "email"); | ||
| ClaimActions.MapJsonKey("urn:meetup:name", "name"); | ||
| ClaimActions.MapJsonKey("urn:meetup:url", "url"); | ||
| } | ||
| } | ||
| } | ||
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.
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.
See #216, it introduces
ClaimTypesconstants for the claims.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.
OK, let me refer to the #216