Skip to content

Commit b927dd6

Browse files
Add Xero provider (#649)
* Xero provider * Update src/AspNet.Security.OAuth.Xero/AspNet.Security.OAuth.Xero.csproj Co-authored-by: Martin Costello <[email protected]> * PR suggestions Co-authored-by: Martin Costello <[email protected]>
1 parent 6276263 commit b927dd6

13 files changed

+729
-0
lines changed

AspNet.Security.OAuth.Providers.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNet.Security.OAuth.Trovo
273273
EndProject
274274
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Twitter", "src\AspNet.Security.OAuth.Twitter\AspNet.Security.OAuth.Twitter.csproj", "{82314BA9-8AB2-46B9-AB12-9109619B8331}"
275275
EndProject
276+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Xero", "src\AspNet.Security.OAuth.Xero\AspNet.Security.OAuth.Xero.csproj", "{1F869094-FAC8-49B5-92A4-706C028CDF93}"
277+
EndProject
276278
Global
277279
GlobalSection(SolutionConfigurationPlatforms) = preSolution
278280
Debug|Any CPU = Debug|Any CPU
@@ -619,6 +621,10 @@ Global
619621
{82314BA9-8AB2-46B9-AB12-9109619B8331}.Debug|Any CPU.Build.0 = Debug|Any CPU
620622
{82314BA9-8AB2-46B9-AB12-9109619B8331}.Release|Any CPU.ActiveCfg = Release|Any CPU
621623
{82314BA9-8AB2-46B9-AB12-9109619B8331}.Release|Any CPU.Build.0 = Release|Any CPU
624+
{1F869094-FAC8-49B5-92A4-706C028CDF93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
625+
{1F869094-FAC8-49B5-92A4-706C028CDF93}.Debug|Any CPU.Build.0 = Debug|Any CPU
626+
{1F869094-FAC8-49B5-92A4-706C028CDF93}.Release|Any CPU.ActiveCfg = Release|Any CPU
627+
{1F869094-FAC8-49B5-92A4-706C028CDF93}.Release|Any CPU.Build.0 = Release|Any CPU
622628
EndGlobalSection
623629
GlobalSection(SolutionProperties) = preSolution
624630
HideSolutionNode = FALSE
@@ -715,6 +721,7 @@ Global
715721
{57633BE6-C7AD-4197-A75A-F38A2312A4D9} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
716722
{DC804C6D-3774-4FA7-8EA6-8C8198995BD6} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
717723
{82314BA9-8AB2-46B9-AB12-9109619B8331} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
724+
{1F869094-FAC8-49B5-92A4-706C028CDF93} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
718725
EndGlobalSection
719726
GlobalSection(ExtensibilityGlobals) = postSolution
720727
SolutionGuid = {C7B54DE2-6407-4802-AD9C-CE54BF414C8C}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ If a provider you're looking for does not exist, consider making a PR to add one
193193
| Weixin (WeChat) | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Weixin?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Weixin/ "Download AspNet.Security.OAuth.Weixin from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Weixin?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Weixin "Download AspNet.Security.OAuth.Weixin from MyGet.org") | [Documentation](https://open.wechat.com/cgi-bin/newreadtemplate?t=overseas_open/docs/web/login/login "WeChat developer documentation") |
194194
| 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") |
195195
| 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") |
196+
| 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") |
196197
| 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") |
197198
| 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") |
198199
| 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
@@ -71,3 +71,4 @@ covered by the section above.
7171
| Vkontakte | _Optional_ | [Documentation](vkontakte.md "Vkontakte provider documentation") |
7272
| Weibo | _Optional_ | [Documentation](weibo.md "Weibo provider documentation") |
7373
| WorkWeixin (WeCom) | _Optional_ | [Documentation](workweixin.md "WorkWeixin provider documentation") |
74+
| Xero | _Optional_ | [Documentation](xero.md "Xero provider documentation") |

docs/xero.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Integrating the Xero Provider
2+
3+
## Example
4+
5+
```csharp
6+
services.AddAuthentication(options => /* Auth configuration */)
7+
.AddXero(options =>
8+
{
9+
options.ClientId = "my-client-id";
10+
options.ClientSecret = "my-client-secret";
11+
12+
// Optionally specify additional scopes, if needed
13+
options.Scope.Add("profile");
14+
options.Scope.Add("email");
15+
});
16+
```
17+
18+
## Required Additional Settings
19+
20+
_None._
21+
22+
## Optional Settings
23+
24+
| Property Name | Property Type | Description | Default Value |
25+
|:--|:--|:--|:--|
26+
| `ConfigurationManager` | `IConfigurationManager<OpenIdConnectConfiguration>?` | The configuration manager to use for the OpenId configuration. | `null` |
27+
| `SecurityTokenHandler` | `JsonWebTokenHandler?` | The JSON Web Token handler to use. | `null` |
28+
| `TokenValidationParameters` | `TokenValidationParameters` | The JSON Web Token validation parameter to use. | `new TokenValidationParameters()` |
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<PackageValidationBaselineVersion>6.0.4</PackageValidationBaselineVersion>
5+
<TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks>
6+
</PropertyGroup>
7+
8+
<!-- TODO Remove once published to NuGet.org -->
9+
<PropertyGroup>
10+
<DisablePackageBaselineValidation>true</DisablePackageBaselineValidation>
11+
</PropertyGroup>
12+
13+
<PropertyGroup>
14+
<Description>ASP.NET Core security middleware enabling Xero authentication.</Description>
15+
<Authors>Albert Zakiev</Authors>
16+
<PackageTags>xero;aspnetcore;authentication;oauth;security</PackageTags>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
21+
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" />
22+
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" />
23+
</ItemGroup>
24+
25+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.Xero;
8+
9+
/// <summary>
10+
/// Contains constants specific to the <see cref="XeroAuthenticationHandler"/>.
11+
/// </summary>
12+
public static class XeroAuthenticationConstants
13+
{
14+
public static class ClaimNames
15+
{
16+
/// <summary>
17+
/// Unique user identifier.
18+
/// </summary>
19+
public const string UserId = "xero_userid";
20+
21+
/// <summary>
22+
/// User email address.
23+
/// </summary>
24+
public const string Email = "email";
25+
}
26+
}
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.Xero;
8+
9+
/// <summary>
10+
/// Default values used by the Xero authentication middleware.
11+
/// </summary>
12+
public static class XeroAuthenticationDefaults
13+
{
14+
/// <summary>
15+
/// Default value for <see cref="AuthenticationScheme.Name"/>.
16+
/// </summary>
17+
public const string AuthenticationScheme = "Xero";
18+
19+
/// <summary>
20+
/// Default value for <see cref="RemoteAuthenticationOptions.CallbackPath"/>.
21+
/// </summary>
22+
public static readonly string CallbackPath = "/signin-xero";
23+
24+
/// <summary>
25+
/// Default value for <see cref="AuthenticationScheme.DisplayName"/>.
26+
/// </summary>
27+
public static readonly string DisplayName = "Xero";
28+
29+
/// <summary>
30+
/// A format string used to construct <see cref="AuthenticationSchemeOptions.ClaimsIssuer"/>.
31+
/// </summary>
32+
public static readonly string ClaimsIssuer = "https://identity.xero.com";
33+
34+
/// <summary>
35+
/// A format string used to populate OAuth authorize endpoint.
36+
/// </summary>
37+
public static readonly string AuthorizeEndpoint = "https://login.xero.com/identity/connect/authorize";
38+
39+
/// <summary>
40+
/// A format string used to populate OAuth token endpoint.
41+
/// </summary>
42+
public static readonly string TokenEndpoint = "https://identity.xero.com/connect/token";
43+
44+
/// <summary>
45+
/// A format string used to construct well-known configuration endpoint.
46+
/// </summary>
47+
public static readonly string MetadataEndpoint = "https://identity.xero.com/.well-known/openid-configuration";
48+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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.Xero;
8+
using Microsoft.Extensions.DependencyInjection.Extensions;
9+
using Microsoft.Extensions.Options;
10+
11+
namespace Microsoft.Extensions.DependencyInjection;
12+
13+
/// <summary>
14+
/// Extension methods to add Xero authentication capabilities to an HTTP application pipeline.
15+
/// </summary>
16+
public static class XeroAuthenticationExtensions
17+
{
18+
/// <summary>
19+
/// Adds <see cref="XeroAuthenticationHandler"/> to the specified
20+
/// <see cref="AuthenticationBuilder"/>, which enables Xero authentication capabilities.
21+
/// </summary>
22+
/// <param name="builder">The <see cref="AuthenticationBuilder"/> to add the middleware to.</param>
23+
/// <returns>A reference to this instance after the operation has completed.</returns>
24+
public static AuthenticationBuilder AddXero([NotNull] this AuthenticationBuilder builder)
25+
=> builder.AddXero(XeroAuthenticationDefaults.AuthenticationScheme, _ => { });
26+
27+
/// <summary>
28+
/// Adds <see cref="XeroAuthenticationHandler"/> to the specified
29+
/// <see cref="AuthenticationBuilder"/>, which enables Xero authentication capabilities.
30+
/// </summary>
31+
/// <param name="builder">The <see cref="AuthenticationBuilder"/> to add the middleware to.</param>
32+
/// <param name="configuration">The delegate used to configure the OAuth 2.0 options.</param>
33+
/// <returns>A reference to this instance after the operation has completed.</returns>
34+
public static AuthenticationBuilder AddXero(
35+
[NotNull] this AuthenticationBuilder builder,
36+
[NotNull] Action<XeroAuthenticationOptions> configuration)
37+
=> builder.AddXero(XeroAuthenticationDefaults.AuthenticationScheme, configuration);
38+
39+
/// <summary>
40+
/// Adds <see cref="XeroAuthenticationHandler"/> to the specified
41+
/// <see cref="AuthenticationBuilder"/>, which enables Xero authentication capabilities.
42+
/// </summary>
43+
/// <param name="builder">The authentication builder.</param>
44+
/// <param name="authenticationScheme">The authentication scheme associated with this instance.</param>
45+
/// <param name="configuration">The delegate used to configure the Xero options.</param>
46+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
47+
public static AuthenticationBuilder AddXero(
48+
[NotNull] this AuthenticationBuilder builder,
49+
[NotNull] string authenticationScheme,
50+
[NotNull] Action<XeroAuthenticationOptions> configuration)
51+
=> builder.AddXero(authenticationScheme, XeroAuthenticationDefaults.DisplayName, configuration);
52+
53+
/// <summary>
54+
/// Adds <see cref="XeroAuthenticationHandler"/> to the specified
55+
/// <see cref="AuthenticationBuilder"/>, which enables Xero authentication capabilities.
56+
/// </summary>
57+
/// <param name="builder">The authentication builder.</param>
58+
/// <param name="authenticationScheme">The authentication scheme associated with this instance.</param>
59+
/// <param name="displayName">The optional display name associated with this instance.</param>
60+
/// <param name="configuration">The delegate used to configure the Xero options.</param>
61+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
62+
public static AuthenticationBuilder AddXero(
63+
[NotNull] this AuthenticationBuilder builder,
64+
[NotNull] string authenticationScheme,
65+
[NotNull] string displayName,
66+
[NotNull] Action<XeroAuthenticationOptions> configuration)
67+
{
68+
builder.Services.TryAddSingleton<IPostConfigureOptions<XeroAuthenticationOptions>, XeroAuthenticationPostConfigureOptions>();
69+
return builder.AddOAuth<XeroAuthenticationOptions, XeroAuthenticationHandler>(authenticationScheme, displayName, configuration);
70+
}
71+
}

0 commit comments

Comments
 (0)