Skip to content

x3rt/x3rt.DiscordOAuth2

Repository files navigation

x3rt.DiscordOAuth2

NuGet NuGet

A simple library to handle Discord OAuth2 authentication. Meant to serve as an alternative to the AspNet.Security.OAuth.Providers library that gives more control to the user and one that can be used by people that are trying to avoid ASP.NETs cluttered and bulky Identity system.

Usage

// Configure OAuth ClientID and ClientSecret globally
DiscordOAuth.Configure(0123456789, "ClientSecret", "OptionalBotToken");
var scopes = new ScopesBuilder(OAuthScope.Identify);
var oAuth = new DiscordOAuth("https://example.com/Login", scopes);
var url = oAuth.GetAuthorizationUrl("state");
/* Redirect user to url via preferred method */
// Your callback method
if (DiscordOAuth.TryGetCode(HttpContext, out var code))
{
    var scopes = new ScopesBuilder(OAuthScope.Identify);
    var oAuth = new DiscordOAuth("https://example.com/Login", scopes);
    var token = await oAuth.GetTokenAsync(code);
    var user = await oAuth.GetUserAsync(token);
    
    ulong userId = user.Id;
    // ...
    
}

Feedback

DiscordOAuth2 is a work in progress and any feedback or suggestions are welcome. This library is released under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages