Skip to content

Commit 41f8a3f

Browse files
Add Xumm provider (#720)
* add Xumm provider * Removed redundant test * Updated package validation base line version
1 parent 8c5892a commit 41f8a3f

File tree

13 files changed

+370
-2
lines changed

13 files changed

+370
-2
lines changed

AspNet.Security.OAuth.Providers.sln

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{C2CA4B38-A
219219
docs\vkontakte.md = docs\vkontakte.md
220220
docs\weibo.md = docs\weibo.md
221221
docs\workweixin.md = docs\workweixin.md
222+
docs\xumm.md = docs\xumm.md
222223
docs\zendesk.md = docs\zendesk.md
223224
EndProjectSection
224225
EndProject
@@ -287,6 +288,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Feish
287288
EndProject
288289
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Kroger", "src\AspNet.Security.OAuth.Kroger\AspNet.Security.OAuth.Kroger.csproj", "{8C7A98A6-5F61-492B-980D-0A9F5F9F5C73}"
289290
EndProject
291+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Xumm", "src\AspNet.Security.OAuth.Xumm\AspNet.Security.OAuth.Xumm.csproj", "{8E42EF81-A630-4BDB-B642-3F20C863F9BE}"
292+
EndProject
290293
Global
291294
GlobalSection(SolutionConfigurationPlatforms) = preSolution
292295
Debug|Any CPU = Debug|Any CPU
@@ -657,6 +660,10 @@ Global
657660
{8C7A98A6-5F61-492B-980D-0A9F5F9F5C73}.Debug|Any CPU.Build.0 = Debug|Any CPU
658661
{8C7A98A6-5F61-492B-980D-0A9F5F9F5C73}.Release|Any CPU.ActiveCfg = Release|Any CPU
659662
{8C7A98A6-5F61-492B-980D-0A9F5F9F5C73}.Release|Any CPU.Build.0 = Release|Any CPU
663+
{8E42EF81-A630-4BDB-B642-3F20C863F9BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
664+
{8E42EF81-A630-4BDB-B642-3F20C863F9BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
665+
{8E42EF81-A630-4BDB-B642-3F20C863F9BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
666+
{8E42EF81-A630-4BDB-B642-3F20C863F9BE}.Release|Any CPU.Build.0 = Release|Any CPU
660667
EndGlobalSection
661668
GlobalSection(SolutionProperties) = preSolution
662669
HideSolutionNode = FALSE
@@ -759,6 +766,7 @@ Global
759766
{ECD22287-9B9F-489A-84A7-E66D65A39D73} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
760767
{B8F9B052-84BF-436C-B22B-CEBD5EB1F8E3} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
761768
{8C7A98A6-5F61-492B-980D-0A9F5F9F5C73} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
769+
{8E42EF81-A630-4BDB-B642-3F20C863F9BE} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
762770
EndGlobalSection
763771
GlobalSection(ExtensibilityGlobals) = postSolution
764772
SolutionGuid = {C7B54DE2-6407-4802-AD9C-CE54BF414C8C}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ If a provider you're looking for does not exist, consider making a PR to add one
206206
| WordPress | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.WordPress?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.WordPress/ "Download AspNet.Security.OAuth.WordPress from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.WordPress?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.WordPress "Download AspNet.Security.OAuth.WordPress from MyGet.org") | [Documentation](https://developer.wordpress.com/docs/oauth2/ "WordPress developer documentation") |
207207
| WorkWeixin (WeCom) | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.WorkWeixin?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.WorkWeixin/ "Download AspNet.Security.OAuth.WorkWeixin from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.WorkWeixin?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.WorkWeixin "Download AspNet.Security.OAuth.WorkWeixin from MyGet.org") | [Documentation](https://open.work.weixin.qq.com/api/doc/ "WorkWeixin developer documentation") |
208208
| Xero | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Xero?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Xero/ "Download AspNet.Security.OAuth.Xero from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Xero?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Xero "Download AspNet.Security.OAuth.Xero from MyGet.org") | [Documentation](https://developer.xero.com/documentation/guides/oauth2/sign-in/ "Xero developer documentation") |
209+
| Xumm | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Xumm?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Xumm/ "Download AspNet.Security.OAuth.Xumm from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Xumm?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Xumm "Download AspNet.Security.OAuth.Xumm from MyGet.org") | [Documentation](https://xumm.readme.io/docs/user-sign-in-identity-provider "Xumm developer documentation") |
209210
| Yahoo | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Yahoo?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Yahoo/ "Download AspNet.Security.OAuth.Yahoo from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Yahoo?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Yahoo "Download AspNet.Security.OAuth.Yahoo from MyGet.org") | [Documentation](https://developer.yahoo.com/oauth2/guide/ "Yahoo developer documentation") |
210211
| Yammer | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Yammer?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Yammer/ "Download AspNet.Security.OAuth.Yammer from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Yammer?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Yammer "Download AspNet.Security.OAuth.Yammer from MyGet.org") | [Documentation](https://developer.yammer.com/docs/oauth-2 "Yammer developer documentation") |
211212
| Yandex | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Yandex?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Yandex/ "Download AspNet.Security.OAuth.Yandex from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Yandex?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Yandex "Download AspNet.Security.OAuth.Yandex from MyGet.org") | [Documentation](https://tech.yandex.com/oauth/ "Yandex developer documentation") |

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ covered by the section above.
7474
| Weibo | _Optional_ | [Documentation](weibo.md "Weibo provider documentation") |
7575
| WorkWeixin (WeCom) | _Optional_ | [Documentation](workweixin.md "WorkWeixin provider documentation") |
7676
| Xero | _Optional_ | [Documentation](xero.md "Xero provider documentation") |
77+
| Xumm | _Optional_ | [Documentation](xumm.md "Xumm provider documentation") |

docs/xumm.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Integrating the Xumm Provider
2+
3+
## Example
4+
5+
```csharp
6+
public void ConfigureServices(IServiceCollection services)
7+
{
8+
services.AddAuthentication(options => /* Auth configuration */)
9+
.AddXumm(options =>
10+
{
11+
options.ClientId = "my-api-key";
12+
options.ClientSecret = "my-api-secret";
13+
});
14+
}
15+
16+
public void Configure(IApplicationBuilder app)
17+
{
18+
app.UseAuthentication();
19+
app.UseAuthorization();
20+
}
21+
```
22+
23+
## Required Additional Settings
24+
25+
_None._

samples/Mvc.Client/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"ClientSecret": "n2Q-GEw9RQjzcRbU3qhfTj8f"
1313
},
1414
"Twitter": {
15-
"ConsumerKey": "6XaCTaLbMqfj6ww3zvZ5g",
16-
"ConsumerSecret": "Il2eFzGIrYhz6BWjYhVXBPQSfZuS4xoHpSSyD9PI"
15+
"ClientId": "6XaCTaLbMqfj6ww3zvZ5g",
16+
"ClientSecret": "Il2eFzGIrYhz6BWjYhVXBPQSfZuS4xoHpSSyD9PI"
1717
}
1818
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks>
5+
<PackageValidationBaselineVersion>6.0.11</PackageValidationBaselineVersion>
6+
<DisablePackageBaselineValidation>true</DisablePackageBaselineValidation>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<Description>ASP.NET Core security middleware enabling Xumm authentication.</Description>
11+
<Authors>Dominique Blomsma</Authors>
12+
<PackageTags>aspnetcore;authentication;oauth;security;xumm</PackageTags>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
17+
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
4+
* for more information concerning the license and the contributors participating to this project.
5+
*/
6+
7+
namespace AspNet.Security.OAuth.Xumm;
8+
9+
/// <summary>
10+
/// Contains constants specific to the <see cref="XummAuthenticationHandler"/>.
11+
/// </summary>
12+
public static class XummAuthenticationConstants
13+
{
14+
public static class Claims
15+
{
16+
public const string Picture = "urn:xumm:picture";
17+
}
18+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
4+
* for more information concerning the license and the contributors participating to this project.
5+
*/
6+
7+
namespace AspNet.Security.OAuth.Xumm;
8+
9+
/// <summary>
10+
/// Default values used by the Xumm authentication middleware.
11+
/// </summary>
12+
public static class XummAuthenticationDefaults
13+
{
14+
/// <summary>
15+
/// Default value for <see cref="AuthenticationScheme.Name"/>.
16+
/// </summary>
17+
public const string AuthenticationScheme = "Xumm";
18+
19+
/// <summary>
20+
/// Default value for <see cref="AuthenticationScheme.DisplayName"/>.
21+
/// </summary>
22+
public static readonly string DisplayName = "Xumm";
23+
24+
/// <summary>
25+
/// Default value for <see cref="AuthenticationSchemeOptions.ClaimsIssuer"/>.
26+
/// </summary>
27+
public static readonly string Issuer = "Xumm";
28+
29+
/// <summary>
30+
/// Default value for <see cref="RemoteAuthenticationOptions.CallbackPath"/>.
31+
/// </summary>
32+
public static readonly string CallbackPath = "/signin-xumm";
33+
34+
/// <summary>
35+
/// Default value for <see cref="OAuthOptions.AuthorizationEndpoint"/>.
36+
/// </summary>
37+
public static readonly string AuthorizationEndpoint = "https://oauth2.xumm.app/auth";
38+
39+
/// <summary>
40+
/// Default value for <see cref="OAuthOptions.TokenEndpoint"/>.
41+
/// </summary>
42+
public static readonly string TokenEndpoint = "https://oauth2.xumm.app/token";
43+
44+
/// <summary>
45+
/// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>.
46+
/// </summary>
47+
public static readonly string UserInformationEndpoint = "https://oauth2.xumm.app/userinfo";
48+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
4+
* for more information concerning the license and the contributors participating to this project.
5+
*/
6+
7+
using AspNet.Security.OAuth.Xumm;
8+
9+
namespace Microsoft.Extensions.DependencyInjection;
10+
11+
/// <summary>
12+
/// Extension methods to add Xumm authentication capabilities to an HTTP application pipeline.
13+
/// </summary>
14+
public static class XummAuthenticationExtensions
15+
{
16+
/// <summary>
17+
/// Adds <see cref="XummAuthenticationHandler"/> to the specified
18+
/// <see cref="AuthenticationBuilder"/>, which enables Xumm authentication capabilities.
19+
/// </summary>
20+
/// <param name="builder">The authentication builder.</param>
21+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
22+
public static AuthenticationBuilder AddXumm([NotNull] this AuthenticationBuilder builder)
23+
{
24+
return builder.AddXumm(XummAuthenticationDefaults.AuthenticationScheme, options => { });
25+
}
26+
27+
/// <summary>
28+
/// Adds <see cref="XummAuthenticationHandler"/> to the specified
29+
/// <see cref="AuthenticationBuilder"/>, which enables Xumm authentication capabilities.
30+
/// </summary>
31+
/// <param name="builder">The authentication builder.</param>
32+
/// <param name="configuration">The delegate used to configure the OpenID 2.0 options.</param>
33+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
34+
public static AuthenticationBuilder AddXumm(
35+
[NotNull] this AuthenticationBuilder builder,
36+
[NotNull] Action<XummAuthenticationOptions> configuration)
37+
{
38+
return builder.AddXumm(XummAuthenticationDefaults.AuthenticationScheme, configuration);
39+
}
40+
41+
/// <summary>
42+
/// Adds <see cref="XummAuthenticationHandler"/> to the specified
43+
/// <see cref="AuthenticationBuilder"/>, which enables Xumm authentication capabilities.
44+
/// </summary>
45+
/// <param name="builder">The authentication builder.</param>
46+
/// <param name="scheme">The authentication scheme associated with this instance.</param>
47+
/// <param name="configuration">The delegate used to configure the Xumm options.</param>
48+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
49+
public static AuthenticationBuilder AddXumm(
50+
[NotNull] this AuthenticationBuilder builder,
51+
[NotNull] string scheme,
52+
[NotNull] Action<XummAuthenticationOptions> configuration)
53+
{
54+
return builder.AddXumm(scheme, XummAuthenticationDefaults.DisplayName, configuration);
55+
}
56+
57+
/// <summary>
58+
/// Adds <see cref="XummAuthenticationHandler"/> to the specified
59+
/// <see cref="AuthenticationBuilder"/>, which enables Xumm authentication capabilities.
60+
/// </summary>
61+
/// <param name="builder">The authentication builder.</param>
62+
/// <param name="scheme">The authentication scheme associated with this instance.</param>
63+
/// <param name="caption">The optional display name associated with this instance.</param>
64+
/// <param name="configuration">The delegate used to configure the Xumm options.</param>
65+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
66+
public static AuthenticationBuilder AddXumm(
67+
[NotNull] this AuthenticationBuilder builder,
68+
[NotNull] string scheme,
69+
[CanBeNull] string caption,
70+
[NotNull] Action<XummAuthenticationOptions> configuration)
71+
{
72+
return builder.AddOAuth<XummAuthenticationOptions, XummAuthenticationHandler>(scheme, caption, configuration);
73+
}
74+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
4+
* for more information concerning the license and the contributors participating to this project.
5+
*/
6+
7+
using System.Net.Http.Headers;
8+
using System.Security.Claims;
9+
using System.Text.Encodings.Web;
10+
using System.Text.Json;
11+
using Microsoft.AspNetCore.WebUtilities;
12+
using Microsoft.Extensions.Logging;
13+
using Microsoft.Extensions.Options;
14+
15+
namespace AspNet.Security.OAuth.Xumm;
16+
17+
public partial class XummAuthenticationHandler : OAuthHandler<XummAuthenticationOptions>
18+
{
19+
public XummAuthenticationHandler(
20+
[NotNull] IOptionsMonitor<XummAuthenticationOptions> options,
21+
[NotNull] ILoggerFactory logger,
22+
[NotNull] UrlEncoder encoder,
23+
[NotNull] ISystemClock clock)
24+
: base(options, logger, encoder, clock)
25+
{
26+
}
27+
28+
protected override async Task<AuthenticationTicket> CreateTicketAsync(
29+
[NotNull] ClaimsIdentity identity,
30+
[NotNull] AuthenticationProperties properties,
31+
[NotNull] OAuthTokenResponse tokens)
32+
{
33+
using var request = new HttpRequestMessage(HttpMethod.Get, Options.UserInformationEndpoint);
34+
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
35+
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken);
36+
37+
using var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
38+
if (!response.IsSuccessStatusCode)
39+
{
40+
await Log.UserProfileErrorAsync(Logger, response, Context.RequestAborted);
41+
throw new HttpRequestException("An error occurred while retrieving the user profile.");
42+
}
43+
44+
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
45+
46+
var principal = new ClaimsPrincipal(identity);
47+
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
48+
context.RunClaimActions();
49+
50+
await Events.CreatingTicket(context);
51+
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
52+
}
53+
54+
private static partial class Log
55+
{
56+
internal static async Task UserProfileErrorAsync(ILogger logger, HttpResponseMessage response, CancellationToken cancellationToken)
57+
{
58+
UserProfileError(
59+
logger,
60+
response.StatusCode,
61+
response.Headers.ToString(),
62+
await response.Content.ReadAsStringAsync(cancellationToken));
63+
}
64+
65+
[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}.")]
66+
private static partial void UserProfileError(
67+
ILogger logger,
68+
System.Net.HttpStatusCode status,
69+
string headers,
70+
string body);
71+
}
72+
}

0 commit comments

Comments
 (0)