Skip to content

Commit

Permalink
Housekeeping.
Browse files Browse the repository at this point in the history
  • Loading branch information
hjdhjd committed Apr 11, 2023
1 parent b1b2f1b commit 7fa77c6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/myq-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class myQApi {
private async oauthLogin(authPage: Response): Promise<Response | null> {

// Grab the cookie for the OAuth sequence. We need to deal with spurious additions to the cookie that gets returned by the myQ API.
const cookie = this.trimSetCookie((authPage.headers as myQHeaders).raw()["set-cookie"] as string[]);
const cookie = this.trimSetCookie((authPage.headers as myQHeaders).raw()["set-cookie"]);

// Parse the myQ login page and grab what we need.
const htmlText = await authPage.text();
Expand Down Expand Up @@ -201,7 +201,7 @@ export class myQApi {

// Cleanup the cookie so we can complete the login process by removing spurious additions
// to the cookie that gets returned by the myQ API.
const cookie = this.trimSetCookie((loginResponse.headers as myQHeaders).raw()["set-cookie"] as string[]);
const cookie = this.trimSetCookie((loginResponse.headers as myQHeaders).raw()["set-cookie"]);

// Execute the redirect with the cleaned up cookies and we're done.
const response = await this.retrieve(redirectUrl.toString(), {
Expand Down Expand Up @@ -683,7 +683,13 @@ export class myQApi {
}

// Utility function to return the relevant portions of the cookies used in the login process.
private trimSetCookie(setCookie: string[]): string {
private trimSetCookie(setCookie: string | string[]): string {

// Let's make sure we're operating on an array that's passed back as a header.
if(!Array.isArray(setCookie)) {

setCookie = [ setCookie ];
}

// We need to strip spurious additions to the cookie that gets returned by the myQ API.
return setCookie.map(x => x.split(";")[0]).join("; ");
Expand Down

0 comments on commit 7fa77c6

Please sign in to comment.