Skip to content
/ Yggdrasil Public

C# wrapper of Yggrasil - the Mojang authentication system.

License

Notifications You must be signed in to change notification settings

Hona/Yggdrasil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 

Repository files navigation

Yggdrasil

Nuget

C# async wrapper of Yggrasil - the Mojang authentication system.

Usage

Authentication

var yggdrasil = new YggdrasilService();
var auth = await yggdrasil.AuthenticateAsync(new AuthenticatePayload
{
    Agent = Agent.Minecraft,
    RequestUser = true,
    Username = "user@email.com",
    Password = "password"
});

if (auth.Success)
{
    // Do something
    Console.WriteLine(auth.Response.AccessToken);
}
else
{
    Console.WriteLine(auth.ErrorResponse.Message);
}

Validation & Refreshing

var authValid = await yggdrasil.ValidateAsync(new ValidatePayload
{
    // Invalid/old token will return invalid
    AccessToken = auth.Response.AccessToken,
    ClientToken = auth.Response.ClientToken
});

if (authValid.Success && 
    authValid.Response == ValidateResponse.Valid)
{
    // We are authenticated
    Console.WriteLine("Valid token");
}
else
{
    // Invalid token, need to refresh
    var refreshAuth = await yggdrasil.RefreshAsync(new RefreshPayload
    {
        AccessToken = auth.Response.AccessToken,
        ClientToken = auth.Response.ClientToken
    });

    if (refreshAuth.Success)
    {
        // Refreshed token successfully
        Console.WriteLine(refreshAuth.Response.AccessToken);
    }
}

Signout (Invalidation using credentials)

var signout = await yggdrasil.SignoutAsync(new SignoutPayload
{
    Username = "user@name.com",
    Password = "password"
});

if (signout.Success && 
    signout.Response == StandardResponse.Success)
{
    Console.WriteLine("All access tokens invalidated.");
}

Invalidation (by tokens)

var invalidate = await yggdrasil.InvalidateAsync(new InvalidatePayload
{
    AccessToken = auth.Response.AccessToken,
    ClientToken = auth.Response.ClientToken
});

if (invalidate.Success &&
    invalidate.Response == StandardResponse.Success)
{
    Console.WriteLine("All access tokens invalidated by tokens.");
}

About

C# wrapper of Yggrasil - the Mojang authentication system.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages