Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supply MSA bearer token directly #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ declare module 'prismarine-auth' {
fetchCertificates?: boolean,
fetchEntitlements?: boolean
fetchProfile?: boolean
msaToken?: string
}): Promise<{ token: string, entitlements: MinecraftJavaLicenses, profile: MinecraftJavaProfile, certificates: MinecraftJavaCertificates }>
// Returns a Minecraft Bedrock Edition auth token. Public key parameter must be a KeyLike object.
getMinecraftBedrockToken(publicKey: KeyObject): Promise<string>
Expand Down
29 changes: 16 additions & 13 deletions src/MicrosoftAuthFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,23 @@ class MicrosoftAuthFlow {

async getMinecraftJavaToken (options = {}) {
const response = { token: '', entitlements: {}, profile: {} }
if (await this.mca.verifyTokens()) {
debug('[mc] Using existing tokens')
const { token } = await this.mca.getCachedAccessToken()
response.token = token

if(options.msaToken) {
response.token = options.msaToken
debug('[mc] Using MSA token directly')
} else {
debug('[mc] Need to obtain tokens')
await retry(async () => {
const xsts = await this.getXboxToken(Endpoints.PCXSTSRelyingParty)
debug('[xbl] xsts data', xsts)
response.token = await this.mca.getAccessToken(xsts)
}, () => { this.xbl.forceRefresh = true }, 2)
if (await this.mca.verifyTokens()) {
debug('[mc] Using existing tokens')
const { token } = await this.mca.getCachedAccessToken()
response.token = token
} else {
debug('[mc] Need to obtain tokens')
await retry(async () => {
const xsts = await this.getXboxToken(Endpoints.PCXSTSRelyingParty)
debug('[xbl] xsts data', xsts)
response.token = await this.mca.getAccessToken(xsts)
}, () => { this.xbl.forceRefresh = true }, 2)
}
}

if (options.fetchEntitlements) {
Expand All @@ -183,9 +189,6 @@ class MicrosoftAuthFlow {
// TODO: Fix cache, in order to do cache we also need to cache the ECDH keys so disable it
// is this even a good idea to cache?
if (await this.mba.verifyTokens() && false) { // eslint-disable-line
debug('[mc] Using existing tokens')
const { chain } = this.mba.getCachedAccessToken()
return chain
} else {
if (!publicKey) throw new Error('Need to specifiy a ECDH x509 URL encoded public key')
debug('[mc] Need to obtain tokens')
Expand Down
Loading