https://github.com/df-mc/go-xsapi
Go library implementing part of the Xbox Services API (XSAPI).
https://github.com/df-mc/go-xsapi
Last synced: about 2 months ago
JSON representation
Go library implementing part of the Xbox Services API (XSAPI).
- Host: GitHub
- URL: https://github.com/df-mc/go-xsapi
- Owner: df-mc
- License: mit
- Created: 2024-09-02T10:16:06.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2026-04-15T09:26:38.000Z (2 months ago)
- Last Synced: 2026-04-15T11:28:48.704Z (2 months ago)
- Language: Go
- Size: 98.6 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-xsapi
[](https://pkg.go.dev/github.com/df-mc/go-xsapi)
>A Go library for communicating with Xbox Live API.

## Example
This code demonstrates Device Authorization Code Flow to retrieve access token, and interacts with some of the API endpoints available in Xbox Live.
```go
// Notify for Ctrl+C and other interrupt signals so the user can abort
// the device authorization flow or other operations at any time.
signals, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
// Use the Device Authorization Flow to sign in to a Microsoft Account.
da, err := MinecraftAndroid.DeviceAuth(signals)
if err != nil {
panic(fmt.Sprintf("error requesting device authorization flow: %s", err))
}
// We print out the verification URI and the user code to [os.Stderr]
// so it doesn't need to be captured by Output: line in this example.
_, _ = fmt.Fprintf(os.Stderr,
"Sign in to your Microsoft Account at %s using the code %s.",
da.VerificationURI, da.UserCode,
)
// Make a context for polling the access token while the user completes sign-in.
// In this case, we allow one minute to complete login (you may configure a longer timeout).
pollCtx, cancel := context.WithTimeout(signals, time.Minute)
defer cancel()
token, err := MinecraftAndroid.DeviceAccessToken(pollCtx, da)
if err != nil {
panic(fmt.Sprintf("error polling access token in device authorization flow: %s", err))
}
// Use TokenSource so we can always use a valid token in fresh state.
msa := MinecraftAndroid.TokenSource(context.Background(), token)
// Make a SISU session using the Microsoft Account token source.
session := MinecraftAndroid.New(msa, nil)
// Log in to Xbox Live services using the SISU session.
client, err := NewClient(session)
if err != nil {
panic(fmt.Sprintf("error creating API client: %s", err))
}
// Make sure to close the client when it's done.
defer func() {
if err := client.Close(); err != nil {
panic(fmt.Sprintf("error closing API client: %s", err))
}
}()
// Use social (peoplehub) endpoint to search a user using the query.
ctx, cancel := context.WithTimeout(signals, time.Second*15)
defer cancel()
users, err := client.Social().Search(ctx, "Lactyy")
if err != nil {
panic(fmt.Sprintf("error searching for users: %s", err))
}
if len(users) == 0 {
panic("no users found")
}
// Use the first user present in the result.
user := users[0]
fmt.Println(user.GamerTag)
```
## Contact
[](https://discord.gg/U4kFWHhTNR)