-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67a2e65
commit 28710a2
Showing
9 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
MinecraftLaunch/Components/Authenticator/UnifiedPassAuthenticator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Flurl.Http; | ||
using MinecraftLaunch.Classes.Interfaces; | ||
using MinecraftLaunch.Classes.Models.Auth; | ||
using MinecraftLaunch.Extensions; | ||
|
||
namespace MinecraftLaunch.Components.Authenticator; | ||
|
||
public class UnifiedPassAuthenticator(string serverId, string userName, string passWord) : IAuthenticator<UnifiedPassAccount> { | ||
private string _serverId = serverId; | ||
private string _userName = userName; | ||
private string _passWord = passWord; | ||
private string _baseUrl = "https://auth.mc-user.com:233/"; | ||
|
||
public void RefreshInformation(string serverId, string userName, string passWord) { | ||
_serverId = serverId; | ||
_passWord = passWord; | ||
_userName = userName; | ||
} | ||
|
||
public UnifiedPassAccount Authenticate() { | ||
return AuthenticateAsync() | ||
.GetAwaiter() | ||
.GetResult(); | ||
} | ||
|
||
public async ValueTask<UnifiedPassAccount> AuthenticateAsync() { | ||
string authUrl = $"{_baseUrl}{_serverId}/authserver/authenticate"; | ||
var content = new { | ||
agent = new { | ||
name = "MinecraftLaunch", | ||
version = 1.00 | ||
}, | ||
username = _userName, | ||
password = _passWord, | ||
clientToken = null as string, | ||
requestUser = true, | ||
}; | ||
|
||
var node = (await (await authUrl.PostJsonAsync(content)) | ||
.GetStringAsync()) | ||
.AsNode(); | ||
|
||
var user = node.GetEnumerable("availableProfiles") | ||
.FirstOrDefault(); | ||
|
||
return new UnifiedPassAccount { | ||
ServerId = _serverId, | ||
Name = user.GetString("name"), | ||
Uuid = Guid.Parse(user.GetString("id")), | ||
AccessToken = node.GetString("accessToken"), | ||
ClientToken = node.GetString("clientToken"), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters