Skip to content

Commit

Permalink
fixed lint errors and minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisj committed Jan 12, 2024
1 parent 736a926 commit c2f65e1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/credentials_provider/http_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function fetchWithCredentials<Credentials, T>(
cancellationToken: CancellationToken = uncancelableToken,
): Promise<T> {
let credentials: CredentialsWithGeneration<Credentials> | undefined;
credentialsLoop: for (let credentialsAttempt = 0; ; ) {
for (let credentialsAttempt = 0; ; ) {
throwIfCanceled(cancellationToken);
if (credentialsAttempt > 1) {
// Don't delay on the first attempt, and also don't delay on the second attempt, since if the
Expand Down
3 changes: 2 additions & 1 deletion src/credentials_provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export abstract class CredentialsProvider<Credentials> extends RefCounted {
if (status === 401) {
// 401: Authorization needed. OAuth2 token may have expired.
return "refresh";
} else if (status === 403 && !credentials.accessToken) {
}
if (status === 403 && !credentials.accessToken) {
// Anonymous access denied. Request credentials.
return "refresh";
}
Expand Down
10 changes: 5 additions & 5 deletions src/datasource/middleauth/credentials_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ async function waitForRemoteFlow(
}

async function waitForLogin(serverUrl: string): Promise<MiddleAuthToken> {
console.log("wait for login");
const data = await waitForRemoteFlow(
`${serverUrl}/api/v1/authorize`,
`middleauth server ${serverUrl} login required.`,
Expand All @@ -127,7 +126,7 @@ async function showTosForm(url: string, tosName: string) {
url,
`Before you can access ${tosName}, you need to accept its Terms of Service.`,
"Open",
`Waiting for Terms of Service agreement...`,
"Waiting for Terms of Service agreement...",
`Terms of Service closed for ${tosName}.`,
);
return data === "success";
Expand Down Expand Up @@ -216,20 +215,20 @@ export class MiddleAuthAppCredentialsProvider extends CredentialsProvider<Middle
error: HttpError,
credentials: OAuth2Credentials,
): Promise<"refresh"> => {
console.log("ma handle error", error);
const { status } = error;
if (status === 401) {
// 401: Authorization needed. OAuth2 token may have expired.
return "refresh";
} else if (status === 403) {
// Anonymous access denied. Request credentials.
}
if (status === 403) {
const { response } = error;
if (response) {
const { headers } = response;
const contentType = headers.get("content-type");
if (contentType === "application/json") {
const json = await response.json();
if (json.error && json.error === "missing_tos") {
// Missing terms of service agreement. Prompt user.
const url = new URL(json.data.tos_form_url);
url.searchParams.set("client", "ng");
const success = await showTosForm(
Expand All @@ -244,6 +243,7 @@ export class MiddleAuthAppCredentialsProvider extends CredentialsProvider<Middle
}
}
if (!credentials.accessToken) {
// Anonymous access denied. Request credentials.
return "refresh";
}
}
Expand Down

0 comments on commit c2f65e1

Please sign in to comment.