Skip to content

Commit 5086a16

Browse files
committed
update docs
1 parent ef3fb19 commit 5086a16

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

MojangAPI/MojangAuth.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ public async Task<MojangAuthResponse> TryAutoLogin()
157157
return res;
158158
}
159159

160+
public async Task<MojangAuthResponse> TryAutoLogin(Session session)
161+
{
162+
MojangAuthResponse res = await Validate(session);
163+
164+
if (!res.IsSuccess)
165+
res = await Refresh(session);
166+
167+
return res;
168+
}
169+
160170
public Task<MojangAuthResponse> Refresh()
161171
{
162172
Session? cachedSession = cacheManager?.ReadCache();

docs/MojangAPI.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ else
2121
}
2222
```
2323

24+
### How to get `AccessToken` or `UUID`?
25+
26+
You can get these token by [Mojang Authentication](./MojangAuth.md) or [Microsoft Xbox Authentication](./XboxAuthentication.md)
27+
2428
### Methods
2529

2630
#### GetUUID
@@ -96,12 +100,14 @@ PlayerProfile profile = await mojang.ChangeName("accessToken", "newName");
96100
#### ChangeSkin
97101

98102
```csharp
103+
// SkinType.Steve or SkinType.Alex
99104
MojangAPIResponse response = await mojang.ChangeSkin("uuid", "accessToken", SkinType.Steve, "skinUrl");
100105
```
101106

102107
#### UploadSkin
103108

104109
```csharp
110+
// SkinType.Steve or SkinType.Alex
105111
MojangAPIResponse response = await mojang.UploadSkin("accessToken", SkinType.Steve, "skin_png_file_path");
106112
```
107113
```csharp

docs/MojangAuth.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## What is Minecraft `Session`?
2+
3+
`Session` is an authentication information, that contains `AccessToken`, `UUID` and `Username`.
4+
`AccessToken` is a temporary token issued after login. ([wiki](https://en.wikipedia.org/wiki/Access_token)).
5+
`UUID` is a unique value given to each player. This value cannot be changed. ([wiki](https://en.wikipedia.org/wiki/Universally_unique_identifier))
6+
`Username` is player name. This value can be changed by user.
7+
8+
Some APIs (changing skin or name, etc) require you `Session`, and you can get this by login.
9+
`MojangAuth` class provides methods to login.
10+
111
## class MojangAuth
212

313
Most methods return `MojangAuthResponse` or class inherited from `MojangAuthResponse`.
@@ -7,6 +17,9 @@ If `IsSuccess` is false, `Result`, `Error`, and `ErrorMessage` property tell you
717

818
`MojangAuth` has its own session caching manager. You don't have to type mojang email and password everytime when you login. Login once using your mojang email and password, and `MojangAuth` will save your session information into json file(not contain your raw password, it contains only tokens). Next time when you login just call `TryAutoLogin`. it authenticate you using cached session without typing mojang email and password.
919

20+
There are two ways to login. One is `Yggdrasil Mojang Authentication` which is described below, and the other is `Microsoft Xbox Authentication` which is new way to login.
21+
[Microsoft Xbox Authentication](./XboxAuthentication.md)
22+
1023
Example:
1124

1225
```csharp

docs/XboxAuthentication.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
writing
1+
## Microsoft Xbox Authentication
2+
3+
[wiki.vg](https://wiki.vg/Microsoft_Authentication_Scheme)
4+
5+
[MojangAuth](./MojangAuth.md) provides methods to authenticate with Minecraft using Xbox game token.
6+
But it does not provide `Microsoft OAuth Flow` and `Xbox Authentication`.
7+
Use another library like [XboxAuthNet](https://github.com/AlphaBs/XboxAuthNet) or [xbox-webapi-csharp](https://github.com/OpenXbox/xbox-webapi-csharp).
8+
9+
You can acquire `XSTSToken` and `ush`(User Hash) through `Microsoft OAuth` and `Xbox Authentication`,.
10+
And then call `RequestSessionWithXbox` method with these values.
11+
12+
Example:
13+
```csharp
14+
HttpClient httpClient = new HttpClient();
15+
MojangAuth auth = new MojangAuth(httpClient);
16+
17+
MojangAuthResponse res = await auth.RequestSessionWithXbox("ush", "XSTSToken");
18+
if (res.IsSuccess)
19+
{
20+
// res.Session.Username
21+
// res.Session.AccessToken
22+
// res.Session.UUID
23+
}
24+
else
25+
{
26+
// res.Result
27+
// res.Error
28+
// res.ErrorMessage
29+
}
30+
```

0 commit comments

Comments
 (0)