Skip to content

Commit

Permalink
Replace oauth-pkce
Browse files Browse the repository at this point in the history
  • Loading branch information
GravlLift committed Sep 10, 2023
1 parent e3988df commit 7c50f4e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
19 changes: 11 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "halo-infinite-api",
"type": "module",
"version": "1.0.3",
"version": "1.0.4",
"description": "An NPM package for accessing the official Halo Infinite API.",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"axios": "^1.3.5",
"luxon": "^3.3.0",
"oauth-pkce": "^0.0.6",
"pkce-challenge": "^4.0.1",
"simple-oauth2": "^5.0.0"
}
}
21 changes: 5 additions & 16 deletions src/authentication/xbox-authentication-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios, { AxiosInstance } from "axios";
import getPkce from "oauth-pkce";
import pkceChallenge from "pkce-challenge";
import { DateTime } from "luxon";
import { XboxTicket } from "../models/xbox-ticket";
import { coalesceDateTime } from "../util/date-time";
Expand Down Expand Up @@ -45,18 +45,7 @@ export class XboxAuthenticationClient {
}

private getPkce() {
return new Promise<{
verifier: string;
challenge: string;
}>((resolve, reject) => {
getPkce(43, (err, { verifier, challenge }) => {
if (err) {
reject(err);
} else {
resolve({ verifier, challenge });
}
});
});
return pkceChallenge(43);
}

public async getAccessToken() {
Expand Down Expand Up @@ -128,7 +117,7 @@ export class XboxAuthenticationClient {
}

private async fetchOauth2Token(): Promise<XboxAuthenticationToken> {
const { verifier, challenge } = await this.getPkce();
const { code_verifier, code_challenge } = await this.getPkce();

const authorizeUrl = `https://login.live.com/oauth20_authorize.srf?${new URLSearchParams(
{
Expand All @@ -137,7 +126,7 @@ export class XboxAuthenticationClient {
redirect_uri: this.redirectUri,
scope: SCOPES.join(" "),
code_challenge_method: "S256",
code_challenge: challenge,
code_challenge,
}
)}`;

Expand All @@ -159,7 +148,7 @@ export class XboxAuthenticationClient {
scope: SCOPES.join(" "),
redirect_uri: this.redirectUri,
client_id: this.clientId,
code_verifier: verifier,
code_verifier,
}),
{
headers: { "Content-Type": "application/x-www-form-urlencoded" },
Expand Down

0 comments on commit 7c50f4e

Please sign in to comment.