diff --git a/Discord.OAuth2/Discord.OAuth2.csproj b/Discord.OAuth2/Discord.OAuth2.csproj deleted file mode 100644 index faa340b..0000000 --- a/Discord.OAuth2/Discord.OAuth2.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - ASP.Net Core middleware that enables an application to support Discord's OAuth 2.0 authentication workflow. - Discord.OAuth2 - Discord.OAuth2 - netstandard2.0 - - - - - diff --git a/Discord.OAuth2/DiscordDefaults.cs b/Discord.OAuth2/DiscordDefaults.cs deleted file mode 100644 index b995c60..0000000 --- a/Discord.OAuth2/DiscordDefaults.cs +++ /dev/null @@ -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"; - } -} diff --git a/Discord.OAuth2/DiscordExtensions.cs b/Discord.OAuth2/DiscordExtensions.cs deleted file mode 100644 index 9ae8269..0000000 --- a/Discord.OAuth2/DiscordExtensions.cs +++ /dev/null @@ -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 configureOptions) - => builder.AddDiscord(DiscordDefaults.AuthenticationScheme, configureOptions); - - public static AuthenticationBuilder AddDiscord(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) - => builder.AddDiscord(authenticationScheme, DiscordDefaults.DisplayName, configureOptions); - - public static AuthenticationBuilder AddDiscord(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) - => builder.AddOAuth(authenticationScheme, displayName, configureOptions); - } -} \ No newline at end of file diff --git a/Discord.OAuth2/DiscordHandler.cs b/Discord.OAuth2/DiscordHandler.cs deleted file mode 100644 index 909b2e5..0000000 --- a/Discord.OAuth2/DiscordHandler.cs +++ /dev/null @@ -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 - { - public DiscordHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) - : base(options, logger, encoder, clock) - { - } - - protected override async Task 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); - } - } -} diff --git a/Discord.OAuth2/DiscordOptions.cs b/Discord.OAuth2/DiscordOptions.cs deleted file mode 100644 index d705c68..0000000 --- a/Discord.OAuth2/DiscordOptions.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.OAuth; -using Microsoft.AspNetCore.Http; -using System.Security.Claims; - -namespace Discord.OAuth2 -{ - /// Configuration options for . - public class DiscordOptions : OAuthOptions - { - /// Initializes a new . - 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); - } - - /// Gets or sets the Discord-assigned appId. - public string AppId { get => ClientId; set => ClientId = value; } - /// Gets or sets the Discord-assigned app secret. - public string AppSecret { get => ClientSecret; set => ClientSecret = value; } - } -} diff --git a/Lieb/DiscordOAuth2/LICENSE b/Lieb/DiscordOAuth2/LICENSE new file mode 100644 index 0000000..84af85b --- /dev/null +++ b/Lieb/DiscordOAuth2/LICENSE @@ -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. diff --git a/Lieb/DiscordOAuth2/readme.txt b/Lieb/DiscordOAuth2/readme.txt new file mode 100644 index 0000000..c47bf4a --- /dev/null +++ b/Lieb/DiscordOAuth2/readme.txt @@ -0,0 +1 @@ +Source: https://github.com/Auralytical/Discord.OAuth2 \ No newline at end of file