Skip to content

Commit 7397cb2

Browse files
Add Zoom provider (#836)
Add Zoom provider.
1 parent e2d2ced commit 7397cb2

File tree

10 files changed

+424
-0
lines changed

10 files changed

+424
-0
lines changed

AspNet.Security.OAuth.Providers.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.PingO
296296
EndProject
297297
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.JumpCloud", "src\AspNet.Security.OAuth.JumpCloud\AspNet.Security.OAuth.JumpCloud.csproj", "{8AF5DDBE-2631-4E71-9045-73A6356CE86B}"
298298
EndProject
299+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Zoom", "src\AspNet.Security.OAuth.Zoom\AspNet.Security.OAuth.Zoom.csproj", "{A4DFC94C-0769-41B3-926C-22642185C878}"
300+
EndProject
299301
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNet.Security.OAuth.Typeform", "src\AspNet.Security.OAuth.Typeform\AspNet.Security.OAuth.Typeform.csproj", "{31333261-A9C2-4AEB-AA6C-AC66DB4FA966}"
300302
EndProject
301303
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNet.Security.OAuth.Calendly", "src\AspNet.Security.OAuth.Calendly\AspNet.Security.OAuth.Calendly.csproj", "{ADAC649F-A8CC-4CF2-8C34-288F7DEBBE69}"
@@ -686,6 +688,10 @@ Global
686688
{8AF5DDBE-2631-4E71-9045-73A6356CE86B}.Debug|Any CPU.Build.0 = Debug|Any CPU
687689
{8AF5DDBE-2631-4E71-9045-73A6356CE86B}.Release|Any CPU.ActiveCfg = Release|Any CPU
688690
{8AF5DDBE-2631-4E71-9045-73A6356CE86B}.Release|Any CPU.Build.0 = Release|Any CPU
691+
{A4DFC94C-0769-41B3-926C-22642185C878}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
692+
{A4DFC94C-0769-41B3-926C-22642185C878}.Debug|Any CPU.Build.0 = Debug|Any CPU
693+
{A4DFC94C-0769-41B3-926C-22642185C878}.Release|Any CPU.ActiveCfg = Release|Any CPU
694+
{A4DFC94C-0769-41B3-926C-22642185C878}.Release|Any CPU.Build.0 = Release|Any CPU
689695
{31333261-A9C2-4AEB-AA6C-AC66DB4FA966}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
690696
{31333261-A9C2-4AEB-AA6C-AC66DB4FA966}.Debug|Any CPU.Build.0 = Debug|Any CPU
691697
{31333261-A9C2-4AEB-AA6C-AC66DB4FA966}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -807,6 +813,7 @@ Global
807813
{101681FB-569F-4941-B943-2AD380039BE0} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
808814
{CF8C4235-6AE6-404E-B572-4FF4E85AB5FF} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
809815
{8AF5DDBE-2631-4E71-9045-73A6356CE86B} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
816+
{A4DFC94C-0769-41B3-926C-22642185C878} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
810817
{31333261-A9C2-4AEB-AA6C-AC66DB4FA966} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
811818
{ADAC649F-A8CC-4CF2-8C34-288F7DEBBE69} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
812819
{83C37AC5-51FB-47CD-8CBE-77AA114FF6F3} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ If a provider you're looking for does not exist, consider making a PR to add one
255255
| 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") |
256256
| Zalo | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Zalo?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Zalo/ "Download AspNet.Security.OAuth.Zalo from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Zalo?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Zalo "Download AspNet.Security.OAuth.Zalo from MyGet.org") | [Documentation](https://developers.zalo.me/docs/api/social-api-4 "Zalo developer documentation") |
257257
| Zendesk | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Zendesk?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Zendesk/ "Download AspNet.Security.OAuth.Zendesk from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Zendesk?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Zendesk "Download AspNet.Security.OAuth.Zendesk from MyGet.org") | [Documentation](https://support.zendesk.com/hc/en-us/articles/203663836#topic_ar1_mfs_qk "Zendesk developer documentation") |
258+
| Zoom | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Zoom?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Zoom/ "Download AspNet.Security.OAuth.Zoom from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Zoom?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Zoom "Download AspNet.Security.OAuth.Zoom from MyGet.org") | [Documentation](https://developers.zoom.us/docs/integrations/ "Zoom developer documentation") |
258259

259260
<!--
260261
| CHANGEME | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.CHANGEME?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.CHANGEME/ "Download AspNet.Security.OAuth.CHANGEME from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.CHANGEME?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.CHANGEME "Download AspNet.Security.OAuth.CHANGEME from MyGet.org") | [Documentation](CHANGEME "CHANGEME developer documentation") |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<PackageValidationBaselineVersion>8.0.1</PackageValidationBaselineVersion>
5+
<TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks>
6+
</PropertyGroup>
7+
8+
<!-- TODO Enable once this provider is published to NuGet.org -->
9+
<PropertyGroup>
10+
<DisablePackageBaselineValidation>true</DisablePackageBaselineValidation>
11+
</PropertyGroup>
12+
13+
<PropertyGroup>
14+
<Description>ASP.NET Core security middleware enabling Zoom authentication.</Description>
15+
<Authors>Christian Oluwawibe</Authors>
16+
<PackageTags>aspnetcore;authentication;zoom;oauth;security</PackageTags>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
21+
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" />
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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.Zoom;
8+
9+
/// <summary>
10+
/// Contains constants specific to the <see cref="ZoomAuthenticationHandler"/>.
11+
/// </summary>
12+
public static class ZoomAuthenticationConstants
13+
{
14+
public static class Claims
15+
{
16+
public const string Picture = "picture";
17+
18+
public const string Email = "email";
19+
20+
public const string NameIdentifier = "id";
21+
22+
public const string Name = "name";
23+
24+
public const string GivenName = "given_name";
25+
26+
public const string FamilyName = "family_name";
27+
28+
public const string PhoneNumber = "phone_number";
29+
30+
public const string Status = "account_status";
31+
32+
public const string Verified = "verified";
33+
34+
public const string PersonalMeetingUrl = "personal_meeting_url";
35+
}
36+
37+
/// <summary>
38+
/// Available profile fields after a Zoom authentication.
39+
/// See <a>https://developers.zoom.us/docs/api/rest/reference/user/methods/#operation/user</a>
40+
/// </summary>
41+
public static class ProfileFields
42+
{
43+
/// <summary>
44+
/// The Unique identifier of the user
45+
/// </summary>
46+
public const string Id = "id";
47+
48+
/// <summary>
49+
/// Display name of the user.
50+
/// </summary>
51+
public const string Name = "display_name";
52+
53+
/// <summary>
54+
/// Given/First name of the user.
55+
/// </summary>
56+
public const string GivenName = "first_name";
57+
58+
/// <summary>
59+
/// Last name of the user.
60+
/// </summary>
61+
public const string FamilyName = "last_name";
62+
63+
/// <summary>
64+
/// Email address of the user.
65+
/// </summary>
66+
public const string Email = "email";
67+
68+
/// <summary>
69+
/// Phone number of the user.
70+
/// </summary>
71+
public const string PhoneNumber = "phone_number";
72+
73+
/// <summary>
74+
/// Picture URL of the user.
75+
/// </summary>
76+
public const string PictureUrl = "pic_url";
77+
78+
/// <summary>
79+
/// AccountStatus of the user.
80+
/// </summary>
81+
public const string Status = "status";
82+
83+
/// <summary>
84+
/// Verification status of the user.
85+
/// </summary>
86+
public const string Verified = "verified";
87+
88+
/// <summary>
89+
/// Personal meeting URL of the user.
90+
/// </summary>
91+
public const string PersonalMeetingUrl = "personal_meeting_url";
92+
}
93+
}
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.Zoom;
8+
9+
/// <summary>
10+
/// Default values used by the Zoom authentication middleware.
11+
/// </summary>
12+
public class ZoomAuthenticationDefaults
13+
{
14+
/// <summary>
15+
/// Default value for <see cref="AuthenticationScheme.Name"/>.
16+
/// </summary>
17+
public const string AuthenticationScheme = "Zoom";
18+
19+
/// <summary>
20+
/// Default value for <see cref="AuthenticationScheme.DisplayName"/>.
21+
/// </summary>
22+
public static readonly string DisplayName = "Zoom";
23+
24+
/// <summary>
25+
/// Default value for <see cref="AuthenticationSchemeOptions.ClaimsIssuer"/>.
26+
/// </summary>
27+
public static readonly string Issuer = "Zoom";
28+
29+
/// <summary>
30+
/// Default value for <see cref="RemoteAuthenticationOptions.CallbackPath"/>.
31+
/// </summary>
32+
public static readonly string CallbackPath = "/signin-zoom";
33+
34+
/// <summary>
35+
/// Default value for <see cref="OAuthOptions.AuthorizationEndpoint"/>.
36+
/// </summary>
37+
public static readonly string AuthorizationEndpoint = "https://zoom.us/oauth/authorize";
38+
39+
/// <summary>
40+
/// Default value for <see cref="OAuthOptions.TokenEndpoint"/>.
41+
/// </summary>
42+
public static readonly string TokenEndpoint = "https://zoom.us/oauth/token";
43+
44+
/// <summary>
45+
/// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>.
46+
/// </summary>
47+
public static readonly string UserInformationEndpoint = "https://api.zoom.us/v2/users/me";
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.Zoom;
8+
9+
namespace Microsoft.Extensions.DependencyInjection;
10+
11+
/// <summary>
12+
/// Extension methods to add Zoom authentication capabilities to an HTTP application pipeline.
13+
/// </summary>
14+
public static class ZoomAuthenticationExtensions
15+
{
16+
/// <summary>
17+
/// Adds <see cref="ZoomAuthenticationHandler"/> to the specified
18+
/// <see cref="AuthenticationBuilder"/>, which enables Zoom authentication capabilities.
19+
/// </summary>
20+
/// <param name="builder">The <see cref="AuthenticationBuilder"/> to add the middleware to.</param>
21+
/// <returns>A reference to this instance after the operation has completed.</returns>
22+
public static AuthenticationBuilder AddZoom([NotNull] this AuthenticationBuilder builder)
23+
{
24+
return builder.AddZoom(ZoomAuthenticationDefaults.AuthenticationScheme, options => { });
25+
}
26+
27+
/// <summary>
28+
/// Adds <see cref="ZoomAuthenticationHandler"/> to the specified
29+
/// <see cref="AuthenticationBuilder"/>, which enables Zoom 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 OpenID 2.0 options.</param>
33+
/// <returns>A reference to this instance after the operation has completed.</returns>
34+
public static AuthenticationBuilder AddZoom(
35+
[NotNull] this AuthenticationBuilder builder,
36+
[NotNull] Action<ZoomAuthenticationOptions> configuration)
37+
{
38+
return builder.AddZoom(ZoomAuthenticationDefaults.AuthenticationScheme, configuration);
39+
}
40+
41+
/// <summary>
42+
/// Adds <see cref="ZoomAuthenticationHandler"/> to the specified
43+
/// <see cref="AuthenticationBuilder"/>, which enables Zoom 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 Zoom options.</param>
48+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
49+
public static AuthenticationBuilder AddZoom(
50+
[NotNull] this AuthenticationBuilder builder,
51+
[NotNull] string scheme,
52+
[NotNull] Action<ZoomAuthenticationOptions> configuration)
53+
{
54+
return builder.AddZoom(scheme, ZoomAuthenticationDefaults.DisplayName, configuration);
55+
}
56+
57+
/// <summary>
58+
/// Adds <see cref="ZoomAuthenticationHandler"/> to the specified
59+
/// <see cref="AuthenticationBuilder"/>, which enables Zoom 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 Zoom options.</param>
65+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
66+
public static AuthenticationBuilder AddZoom(
67+
[NotNull] this AuthenticationBuilder builder,
68+
[NotNull] string scheme,
69+
[CanBeNull] string caption,
70+
[NotNull] Action<ZoomAuthenticationOptions> configuration)
71+
{
72+
return builder.AddOAuth<ZoomAuthenticationOptions, ZoomAuthenticationHandler>(scheme, caption, configuration);
73+
}
74+
}
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 System.Net.Http.Headers;
8+
using System.Security.Claims;
9+
using System.Text.Encodings.Web;
10+
using System.Text.Json;
11+
using Microsoft.Extensions.Logging;
12+
using Microsoft.Extensions.Options;
13+
14+
namespace AspNet.Security.OAuth.Zoom;
15+
16+
public partial class ZoomAuthenticationHandler : OAuthHandler<ZoomAuthenticationOptions>
17+
{
18+
public ZoomAuthenticationHandler(
19+
[NotNull] IOptionsMonitor<ZoomAuthenticationOptions> options,
20+
[NotNull] ILoggerFactory logger,
21+
[NotNull] UrlEncoder encoder)
22+
: base(options, logger, encoder)
23+
{
24+
}
25+
26+
protected override async Task<AuthenticationTicket> CreateTicketAsync(
27+
[NotNull] ClaimsIdentity identity,
28+
[NotNull] AuthenticationProperties properties,
29+
[NotNull] OAuthTokenResponse tokens)
30+
{
31+
var requestUri = Options.UserInformationEndpoint;
32+
33+
using var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
34+
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken);
35+
36+
using var response = await Backchannel.SendAsync(request, Context.RequestAborted);
37+
if (!response.IsSuccessStatusCode)
38+
{
39+
await Log.UserProfileErrorAsync(Logger, response, Context.RequestAborted);
40+
throw new HttpRequestException("An error occurred while retrieving the user profile.");
41+
}
42+
43+
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
44+
45+
var principal = new ClaimsPrincipal(identity);
46+
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
47+
context.RunClaimActions();
48+
49+
await Events.CreatingTicket(context);
50+
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
51+
}
52+
53+
private static partial class Log
54+
{
55+
internal static async Task UserProfileErrorAsync(ILogger logger, HttpResponseMessage response, CancellationToken cancellationToken)
56+
{
57+
UserProfileError(
58+
logger,
59+
response.StatusCode,
60+
response.Headers.ToString(),
61+
await response.Content.ReadAsStringAsync(cancellationToken));
62+
}
63+
64+
[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}.")]
65+
static partial void UserProfileError(
66+
ILogger logger,
67+
System.Net.HttpStatusCode status,
68+
string headers,
69+
string body);
70+
}
71+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.Security.Claims;
8+
using static AspNet.Security.OAuth.Zoom.ZoomAuthenticationConstants;
9+
10+
namespace AspNet.Security.OAuth.Zoom;
11+
12+
/// <summary>
13+
/// Defines a set of options used by <see cref="ZoomAuthenticationHandler"/>.
14+
/// </summary>
15+
public class ZoomAuthenticationOptions : OAuthOptions
16+
{
17+
public ZoomAuthenticationOptions()
18+
{
19+
ClaimsIssuer = ZoomAuthenticationDefaults.Issuer;
20+
CallbackPath = ZoomAuthenticationDefaults.CallbackPath;
21+
22+
AuthorizationEndpoint = ZoomAuthenticationDefaults.AuthorizationEndpoint;
23+
TokenEndpoint = ZoomAuthenticationDefaults.TokenEndpoint;
24+
UserInformationEndpoint = ZoomAuthenticationDefaults.UserInformationEndpoint;
25+
UsePkce = true;
26+
27+
ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, ProfileFields.Id);
28+
ClaimActions.MapJsonKey(ClaimTypes.Name, ProfileFields.Name);
29+
ClaimActions.MapJsonKey(ClaimTypes.Email, ProfileFields.Email);
30+
ClaimActions.MapJsonKey(ClaimTypes.GivenName, ProfileFields.GivenName);
31+
ClaimActions.MapJsonKey(ClaimTypes.Surname, ProfileFields.FamilyName);
32+
ClaimActions.MapJsonKey(Claims.Picture, ProfileFields.PictureUrl);
33+
ClaimActions.MapJsonKey(ClaimTypes.MobilePhone, ProfileFields.PhoneNumber);
34+
ClaimActions.MapJsonKey(Claims.Status, ProfileFields.Status);
35+
ClaimActions.MapJsonKey(Claims.Verified, ProfileFields.Verified);
36+
ClaimActions.MapJsonKey(Claims.PersonalMeetingUrl, ProfileFields.PersonalMeetingUrl);
37+
}
38+
}

0 commit comments

Comments
 (0)