Skip to content

Commit

Permalink
Fixed authentication issue due to School Pass changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bootsie123 committed May 9, 2024
1 parent 90dbec2 commit f21e8f8
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/lib/SchoolPass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ export interface SchoolPassBusBoardingManifestReportItem {
externalID?: string;
}

/**
* Outlines a token returned from the School Pass API
*/
interface SchoolPassAPIToken {
access_token: string;
access_token_expirate: Date;
refresh_token: string;
}

/**
* Responsible for handling all communication with the SchoolPass API
*/
Expand Down Expand Up @@ -162,7 +171,7 @@ export class SchoolPassAPI {
environment.schoolPass.password
);

originalReq.headers.Token = token;
originalReq.headers["Authorization"] = `Bearer ${token.access_token}`;

return http(originalReq);
} catch {
Expand Down Expand Up @@ -226,10 +235,10 @@ export class SchoolPassAPI {
this.schoolCode,
userInfo.userType,
userInfo.internalId,
hash
environment.schoolPass.password
);

this.http.defaults.headers.common.Authorization = `Bearer ${token}`;
this.http.defaults.headers.common.Authorization = `Bearer ${token.access_token}`;
} catch (err) {
this.logger.log(Severity.Error, err);

Expand Down Expand Up @@ -282,17 +291,14 @@ export class SchoolPassAPI {
userType: number,
userId: number,
password: string
): Promise<string> {
): Promise<SchoolPassAPIToken> {
try {
const res = await this.http.post(
"Auth/token",
{
schoolCode,
userType,
userId,
password
}
);
const res = await this.http.post("Auth/token", {
schoolCode,
userType,
userId,
password
});

return res.data;
} catch (err) {
Expand Down

0 comments on commit f21e8f8

Please sign in to comment.