-
Notifications
You must be signed in to change notification settings - Fork 546
Adds Miro provider #1046
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
Merged
Merged
Adds Miro provider #1046
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3f7defb
Adds Miro provider
jerriep 7056748
Update src/AspNet.Security.OAuth.Miro/MiroAuthenticationExtensions.cs
jerriep 06871cf
Update src/AspNet.Security.OAuth.Miro/AspNet.Security.OAuth.Miro.csproj
jerriep bdafaaa
Adds Miro NuGet and developer docs to the readme
jerriep b1dfc57
Merge branch 'dev' into add-miro
martincostello 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,25 @@ | ||
| # Integrating the Miro Provider | ||
|
|
||
| ## Example | ||
|
|
||
| ```csharp | ||
| services.AddAuthentication(options => /* Auth configuration */) | ||
| .AddMiro(options => | ||
| { | ||
| options.ClientId = configuration["Miro:ClientId"] ?? string.Empty; | ||
| options.ClientSecret = configuration["Miro:ClientSecret"] ?? string.Empty; | ||
| }) | ||
| ``` | ||
|
|
||
| ## Required Additional Settings | ||
|
|
||
| _None._ | ||
|
|
||
| ## Optional Settings | ||
|
|
||
| _None._ | ||
|
|
||
| ## Retrieving the user's email address | ||
|
|
||
| The Miro provider does not return the user's email address, since the API endpoints to do that is available only on the Miro Enterprise plan. If you are on the Miro Enterprise plan, you can use the access token returned by the authentication flow to retrieve the user's email address yourself by following the Miro documentation for [getting the user info and email](https://developers.miro.com/docs/get-user-info-and-email). | ||
|
|
21 changes: 21 additions & 0 deletions
21
src/AspNet.Security.OAuth.Miro/AspNet.Security.OAuth.Miro.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>9.2.0</PackageValidationBaselineVersion> | ||
| <!-- TODO Remove once published to NuGet.org --> | ||
| <DisablePackageBaselineValidation>true</DisablePackageBaselineValidation> | ||
| <TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <Description>ASP.NET Core security middleware enabling Miro authentication.</Description> | ||
| <Authors>Jerrie Pelser</Authors> | ||
| <PackageTags>aspnetcore;authentication;miro;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.Miro/MiroAuthenticationConstants.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. | ||
| */ | ||
|
|
||
| namespace AspNet.Security.OAuth.Miro; | ||
|
|
||
| /// <summary> | ||
| /// Contains constants specific to the <see cref="MiroAuthenticationHandler"/>. | ||
| /// </summary> | ||
| public static class MiroAuthenticationConstants | ||
| { | ||
| public static class Claims | ||
| { | ||
| public const string OrganizationId = "urn:miro:organization_id"; | ||
|
|
||
| public const string OrganizationName = "urn:miro:organization_name"; | ||
|
|
||
| public const string TeamId = "urn:miro:team_id"; | ||
|
|
||
| public const string TeamName = "urn:miro:team_name"; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
src/AspNet.Security.OAuth.Miro/MiroAuthenticationDefaults.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,48 @@ | ||
| /* | ||
| * 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.Miro; | ||
|
|
||
| /// <summary> | ||
| /// Default values used by the Miro authentication middleware. | ||
| /// </summary> | ||
| public class MiroAuthenticationDefaults | ||
| { | ||
| /// <summary> | ||
| /// Default value for <see cref="AuthenticationScheme.Name"/>. | ||
| /// </summary> | ||
| public const string AuthenticationScheme = "Miro"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="AuthenticationScheme.DisplayName"/>. | ||
| /// </summary> | ||
| public static readonly string DisplayName = "Miro"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="AuthenticationSchemeOptions.ClaimsIssuer"/>. | ||
| /// </summary> | ||
| public static readonly string Issuer = "Miro"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="RemoteAuthenticationOptions.CallbackPath"/>. | ||
| /// </summary> | ||
| public static readonly string CallbackPath = "/signin-miro"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="OAuthOptions.AuthorizationEndpoint"/>. | ||
| /// </summary> | ||
| public static readonly string AuthorizationEndpoint = "https://miro.com/oauth/authorize"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="OAuthOptions.TokenEndpoint"/>. | ||
| /// </summary> | ||
| public static readonly string TokenEndpointFormat = "https://api.miro.com/v1/oauth/token"; | ||
|
|
||
| /// <summary> | ||
| /// Default value <see cref="OAuthOptions.UserInformationEndpoint"/>. | ||
| /// </summary> | ||
| public static readonly string UserInformationEndpoint = "https://api.miro.com/v1/oauth-token"; | ||
| } |
71 changes: 71 additions & 0 deletions
71
src/AspNet.Security.OAuth.Miro/MiroAuthenticationExtensions.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,71 @@ | ||
| /* | ||
| * 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.Miro; | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| public static class MiroAuthenticationExtensions | ||
| { | ||
| /// <summary> | ||
| /// Adds <see cref="MiroAuthenticationHandler"/> to the specified | ||
| /// <see cref="AuthenticationBuilder"/>, which enables Miro authentication capabilities. | ||
| /// </summary> | ||
| /// <param name="builder">The authentication builder.</param> | ||
| /// <returns>A reference to this instance after the operation has completed.</returns> | ||
| public static AuthenticationBuilder AddMiro([NotNull] this AuthenticationBuilder builder) | ||
| { | ||
| return builder.AddMiro(MiroAuthenticationDefaults.AuthenticationScheme, options => { }); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds <see cref="MiroAuthenticationHandler"/> to the specified | ||
| /// <see cref="AuthenticationBuilder"/>, which enables Miro authentication capabilities. | ||
| /// </summary> | ||
| /// <param name="builder">The authentication builder.</param> | ||
| /// <param name="configuration">The delegate used to configure the Miro authentication options.</param> | ||
| /// <returns>A reference to this instance after the operation has completed.</returns> | ||
| public static AuthenticationBuilder AddMiro( | ||
| [NotNull] this AuthenticationBuilder builder, | ||
| [NotNull] Action<MiroAuthenticationOptions> configuration) | ||
| { | ||
| return builder.AddMiro(MiroAuthenticationDefaults.AuthenticationScheme, configuration); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds <see cref="AspNet.Security.OAuth.Miro.MiroAuthenticationHandler"/> to the specified | ||
| /// <see cref="AuthenticationBuilder"/>, which enables Miro 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 Miro authentication options.</param> | ||
| /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> | ||
| public static AuthenticationBuilder AddMiro( | ||
| [NotNull] this AuthenticationBuilder builder, | ||
| [NotNull] string scheme, | ||
| [NotNull] Action<MiroAuthenticationOptions> configuration) | ||
| { | ||
| return builder.AddMiro(scheme, MiroAuthenticationDefaults.DisplayName, configuration); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds <see cref="AspNet.Security.OAuth.Miro.MiroAuthenticationHandler"/> to the specified | ||
| /// <see cref="AuthenticationBuilder"/>, which enables Miro 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 Miro authentication options.</param> | ||
| /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> | ||
| public static AuthenticationBuilder AddMiro( | ||
| [NotNull] this AuthenticationBuilder builder, | ||
| [NotNull] string scheme, | ||
| [NotNull] string caption, | ||
| [NotNull] Action<MiroAuthenticationOptions> configuration) | ||
| { | ||
| return builder.AddOAuth<MiroAuthenticationOptions, MiroAuthenticationHandler>(scheme, caption, configuration); | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
src/AspNet.Security.OAuth.Miro/MiroAuthenticationHandler.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,68 @@ | ||
| /* | ||
| * 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.Net.Http.Headers; | ||
| using System.Security.Claims; | ||
| using System.Text.Encodings.Web; | ||
| using System.Text.Json; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Extensions.Options; | ||
|
|
||
| namespace AspNet.Security.OAuth.Miro; | ||
|
|
||
| public partial class MiroAuthenticationHandler( | ||
| [NotNull] IOptionsMonitor<MiroAuthenticationOptions> options, | ||
| [NotNull] ILoggerFactory logger, | ||
| [NotNull] UrlEncoder encoder) | ||
| : OAuthHandler<MiroAuthenticationOptions>(options, logger, encoder) | ||
| { | ||
| protected override async Task<AuthenticationTicket> CreateTicketAsync( | ||
| [NotNull] ClaimsIdentity identity, | ||
| [NotNull] AuthenticationProperties properties, | ||
| [NotNull] OAuthTokenResponse tokens) | ||
| { | ||
| using var request = new HttpRequestMessage(HttpMethod.Get, Options.UserInformationEndpoint); | ||
| request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
| request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken); | ||
|
|
||
| using var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted); | ||
| if (!response.IsSuccessStatusCode) | ||
| { | ||
| await Log.UserProfileErrorAsync(Logger, response, Context.RequestAborted); | ||
| throw new HttpRequestException("An error occurred while retrieving the user profile from Miro."); | ||
| } | ||
|
|
||
| using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted)); | ||
|
|
||
| var principal = new ClaimsPrincipal(identity); | ||
| var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement); | ||
| context.RunClaimActions(); | ||
|
|
||
| await Events.CreatingTicket(context); | ||
| return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name); | ||
| } | ||
|
|
||
| private static partial class Log | ||
| { | ||
| internal static async Task UserProfileErrorAsync(ILogger logger, HttpResponseMessage response, CancellationToken cancellationToken) | ||
| { | ||
| UserProfileError( | ||
| logger, | ||
| response.StatusCode, | ||
| response.Headers.ToString(), | ||
| await response.Content.ReadAsStringAsync(cancellationToken)); | ||
| } | ||
|
|
||
| [LoggerMessage(1, | ||
| LogLevel.Error, | ||
| "An error occurred while retrieving the user profile: the remote server returned a {Status} response with the following payload: {Headers} {Body}.")] | ||
| private static partial void UserProfileError( | ||
| ILogger logger, | ||
| System.Net.HttpStatusCode status, | ||
| string headers, | ||
| string body); | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
src/AspNet.Security.OAuth.Miro/MiroAuthenticationOptions.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,30 @@ | ||
| /* | ||
| * 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 static AspNet.Security.OAuth.Miro.MiroAuthenticationConstants; | ||
|
|
||
| namespace AspNet.Security.OAuth.Miro; | ||
|
|
||
| public class MiroAuthenticationOptions : OAuthOptions | ||
| { | ||
| public MiroAuthenticationOptions() | ||
| { | ||
| ClaimsIssuer = MiroAuthenticationDefaults.Issuer; | ||
| CallbackPath = MiroAuthenticationDefaults.CallbackPath; | ||
|
|
||
| AuthorizationEndpoint = MiroAuthenticationDefaults.AuthorizationEndpoint; | ||
| TokenEndpoint = MiroAuthenticationDefaults.TokenEndpointFormat; | ||
| UserInformationEndpoint = MiroAuthenticationDefaults.UserInformationEndpoint; | ||
|
|
||
| ClaimActions.MapJsonSubKey(ClaimTypes.NameIdentifier, "user", "id"); | ||
| ClaimActions.MapJsonSubKey(ClaimTypes.Name, "user", "name"); | ||
| ClaimActions.MapJsonSubKey(Claims.OrganizationId, "organization", "id"); | ||
| ClaimActions.MapJsonSubKey(Claims.OrganizationName, "organization", "name"); | ||
| ClaimActions.MapJsonSubKey(Claims.TeamId, "team", "id"); | ||
| ClaimActions.MapJsonSubKey(Claims.TeamName, "team", "name"); | ||
| } | ||
| } |
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.