Skip to content

Commit

Permalink
Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shenj committed Dec 24, 2024
1 parent e5d113b commit 8821c6b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
8 changes: 8 additions & 0 deletions lib/msal-custom-auth/src/CustomAuthConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Licensed under the MIT License.
*/

import { Constants } from "@azure/msal-browser";

export const GrantType = {
PASSWORD: "password",
OOB: "oob",
Expand All @@ -16,3 +18,9 @@ export const ChallengeType = {
OOB: "oob",
REDIRECT: "redirect",
};

export const DefaultScopes = [
Constants.OPENID_SCOPE,
Constants.PROFILE_SCOPE,
Constants.OFFLINE_ACCESS_SCOPE,
];
47 changes: 18 additions & 29 deletions lib/msal-custom-auth/src/account/auth_flow/model/AccountInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
GetAccessTokenError,
InvalidScopes,
} from "../../../core/error/GetAccessTokenError.js";
import { DefaultScopes } from "../../../CustomAuthConstants.js";

/*
* Account information.
Expand Down Expand Up @@ -73,17 +74,7 @@ export class AccountInfo {
* Gets the token claims.
* @returns The token claims.
*/
getClaims():
| (TokenClaims & {
[key: string]:
| string
| number
| string[]
| object
| undefined
| unknown;
})
| undefined {
getClaims(): AuthTokenClaims | undefined {
return this.account.idTokenClaims;
}

Expand All @@ -97,26 +88,24 @@ export class AccountInfo {
forceRefresh: boolean = false,
scopes?: Array<string>
): Promise<GetAccessTokenResult> {
const newScopes = scopes || [
Constants.OPENID_SCOPE,
Constants.PROFILE_SCOPE,
Constants.OFFLINE_ACCESS_SCOPE,
];

if (newScopes.length === 0) {
const errorResult = GetAccessTokenResult.createWithError(
new GetAccessTokenError(
InvalidScopes,
"Empty scopes",
this.correlationId
)
);

return Promise.resolve(errorResult);
}
const newScopes = scopes || DefaultScopes;

throw new Error(
`Method not implemented with forceRefresh '${forceRefresh}'.`
`Method not implemented with forceRefresh '${forceRefresh}' and scopes ${newScopes}.`
);
}
}

/*
* Authentication token claims.
*/
type AuthTokenClaims =
| TokenClaims & {
[key: string]:
| string
| number
| string[]
| object
| undefined
| unknown;
};

0 comments on commit 8821c6b

Please sign in to comment.