Cleaned up Project
Added License of DiscordOAuth2
This commit is contained in:
parent
87c68fbcf7
commit
73441d920f
7 changed files with 22 additions and 119 deletions
|
@ -1,12 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="../Discord.OAuth2.targets" />
|
||||
<PropertyGroup>
|
||||
<Description>ASP.Net Core middleware that enables an application to support Discord's OAuth 2.0 authentication workflow.</Description>
|
||||
<RootNamespace>Discord.OAuth2</RootNamespace>
|
||||
<AssemblyName>Discord.OAuth2</AssemblyName>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OAuth" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,12 +0,0 @@
|
|||
namespace Discord.OAuth2
|
||||
{
|
||||
public static class DiscordDefaults
|
||||
{
|
||||
public const string AuthenticationScheme = "Discord";
|
||||
public const string DisplayName = "Discord";
|
||||
|
||||
public static readonly string AuthorizationEndpoint = "https://discordapp.com/api/oauth2/authorize";
|
||||
public static readonly string TokenEndpoint = "https://discordapp.com/api/oauth2/token";
|
||||
public static readonly string UserInformationEndpoint = "https://discordapp.com/api/users/@me";
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Discord.OAuth2;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
public static class DiscordAuthenticationOptionsExtensions
|
||||
{
|
||||
public static AuthenticationBuilder AddDiscord(this AuthenticationBuilder builder)
|
||||
=> builder.AddDiscord(DiscordDefaults.AuthenticationScheme, _ => { });
|
||||
|
||||
public static AuthenticationBuilder AddDiscord(this AuthenticationBuilder builder, Action<DiscordOptions> configureOptions)
|
||||
=> builder.AddDiscord(DiscordDefaults.AuthenticationScheme, configureOptions);
|
||||
|
||||
public static AuthenticationBuilder AddDiscord(this AuthenticationBuilder builder, string authenticationScheme, Action<DiscordOptions> configureOptions)
|
||||
=> builder.AddDiscord(authenticationScheme, DiscordDefaults.DisplayName, configureOptions);
|
||||
|
||||
public static AuthenticationBuilder AddDiscord(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action<DiscordOptions> configureOptions)
|
||||
=> builder.AddOAuth<DiscordOptions, DiscordHandler>(authenticationScheme, displayName, configureOptions);
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.OAuth;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Claims;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.OAuth2
|
||||
{
|
||||
internal class DiscordHandler : OAuthHandler<DiscordOptions>
|
||||
{
|
||||
public DiscordHandler(IOptionsMonitor<DiscordOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock)
|
||||
: base(options, logger, encoder, clock)
|
||||
{
|
||||
}
|
||||
|
||||
protected override async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens)
|
||||
{
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, Options.UserInformationEndpoint);
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken);
|
||||
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
var response = await Backchannel.SendAsync(request, Context.RequestAborted);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
throw new HttpRequestException($"Failed to retrieve Discord user information ({response.StatusCode}).");
|
||||
|
||||
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
|
||||
|
||||
var context = new OAuthCreatingTicketContext(new ClaimsPrincipal(identity), properties, Context, Scheme, Options, Backchannel, tokens, payload);
|
||||
context.RunClaimActions();
|
||||
|
||||
await Events.CreatingTicket(context);
|
||||
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.OAuth;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Discord.OAuth2
|
||||
{
|
||||
/// <summary> Configuration options for <see cref="DiscordHandler"/>. </summary>
|
||||
public class DiscordOptions : OAuthOptions
|
||||
{
|
||||
/// <summary> Initializes a new <see cref="DiscordOptions"/>. </summary>
|
||||
public DiscordOptions()
|
||||
{
|
||||
CallbackPath = new PathString("/signin-discord");
|
||||
AuthorizationEndpoint = DiscordDefaults.AuthorizationEndpoint;
|
||||
TokenEndpoint = DiscordDefaults.TokenEndpoint;
|
||||
UserInformationEndpoint = DiscordDefaults.UserInformationEndpoint;
|
||||
Scope.Add("identify");
|
||||
|
||||
ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id", ClaimValueTypes.UInteger64);
|
||||
ClaimActions.MapJsonKey(ClaimTypes.Name, "username", ClaimValueTypes.String);
|
||||
ClaimActions.MapJsonKey(ClaimTypes.Email, "email", ClaimValueTypes.Email);
|
||||
ClaimActions.MapJsonKey("urn:discord:discriminator", "discriminator", ClaimValueTypes.UInteger32);
|
||||
ClaimActions.MapJsonKey("urn:discord:avatar", "avatar", ClaimValueTypes.String);
|
||||
ClaimActions.MapJsonKey("urn:discord:verified", "verified", ClaimValueTypes.Boolean);
|
||||
}
|
||||
|
||||
/// <summary> Gets or sets the Discord-assigned appId. </summary>
|
||||
public string AppId { get => ClientId; set => ClientId = value; }
|
||||
/// <summary> Gets or sets the Discord-assigned app secret. </summary>
|
||||
public string AppSecret { get => ClientSecret; set => ClientSecret = value; }
|
||||
}
|
||||
}
|
21
Lieb/DiscordOAuth2/LICENSE
Normal file
21
Lieb/DiscordOAuth2/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016-2018 RogueException
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
1
Lieb/DiscordOAuth2/readme.txt
Normal file
1
Lieb/DiscordOAuth2/readme.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Source: https://github.com/Auralytical/Discord.OAuth2
|
Loading…
Add table
Add a link
Reference in a new issue