https://github.com/hona/yggdrasil
C# wrapper of Yggrasil - the Mojang authentication system.
https://github.com/hona/yggdrasil
Last synced: 3 months ago
JSON representation
C# wrapper of Yggrasil - the Mojang authentication system.
- Host: GitHub
- URL: https://github.com/hona/yggdrasil
- Owner: Hona
- License: gpl-3.0
- Created: 2020-06-27T10:54:23.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T10:49:09.000Z (over 2 years ago)
- Last Synced: 2025-01-21T09:48:45.584Z (4 months ago)
- Language: C#
- Size: 46.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yggdrasil
[](https://www.nuget.org/packages/Yggdrasil.NET)C# async wrapper of Yggrasil - the Mojang authentication system.
## Usage
### Authentication
```cs
var yggdrasil = new YggdrasilService();
var auth = await yggdrasil.AuthenticateAsync(new AuthenticatePayload
{
Agent = Agent.Minecraft,
RequestUser = true,
Username = "[email protected]",
Password = "password"
});if (auth.Success)
{
// Do something
Console.WriteLine(auth.Response.AccessToken);
}
else
{
Console.WriteLine(auth.ErrorResponse.Message);
}
```### Validation & Refreshing
```cs
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)
```cs
var signout = await yggdrasil.SignoutAsync(new SignoutPayload
{
Username = "[email protected]",
Password = "password"
});if (signout.Success &&
signout.Response == StandardResponse.Success)
{
Console.WriteLine("All access tokens invalidated.");
}
```### Invalidation (by tokens)
```cs
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.");
}
```