Skip to content

Instance Discovery 2.x #1756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f3b6117
Port changes from msal-core
tnorling Jun 5, 2020
7ae8baf
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
tnorling Jun 18, 2020
6025e84
Add support for preferred_cache and preferred_network
tnorling Jun 18, 2020
7872ca2
Update references to old temp constant
tnorling Jun 18, 2020
dcaff8e
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
tnorling Jun 18, 2020
a71e396
Cleanup getInstanceMetadata
tnorling Jun 18, 2020
b9d4e62
Cleanup
tnorling Jun 18, 2020
9d10e65
Update node and browser
tnorling Jun 18, 2020
2600876
Adding code for instance_aware authentication in msal-browser
pkanher617 Jun 19, 2020
5307fa8
Adding graph hostname and graph host to the auth result
pkanher617 Jun 19, 2020
710075d
Adding AuthCodePayload object
pkanher617 Jun 19, 2020
d96595f
Rename AuthCodeResponse file
pkanher617 Jun 19, 2020
b2c6aa7
Update PublicClientApplication.ts
pkanher617 Jun 19, 2020
53de8da
adding instance aware sample
pkanher617 Jun 19, 2020
171d4d0
Remove policy from createAccount
tnorling Jun 19, 2020
570b361
Update environment for adfs
tnorling Jun 19, 2020
55f7be5
All common tests passing
tnorling Jun 19, 2020
4aead0a
Browser tests passing
tnorling Jun 19, 2020
4f15a91
Add tests
tnorling Jun 19, 2020
4662361
Merge branch 'instance-aware-2.0' of https://github.com/AzureAD/micro…
tnorling Jun 19, 2020
0dddb02
Add error
tnorling Jun 19, 2020
ed17743
Update untrustedAuthority error message
tnorling Jun 19, 2020
27b0530
Address feedback
tnorling Jun 20, 2020
f939af1
Address feedback
tnorling Jun 20, 2020
045acbe
Revert VScode settings
tnorling Jun 20, 2020
da430bd
Revert VScode settings
tnorling Jun 20, 2020
663e604
Add performance doc
tnorling Jun 22, 2020
4d35732
Add performance doc
tnorling Jun 22, 2020
811121a
Revert "Add performance doc"
tnorling Jun 22, 2020
d4686bd
Revert "Add performance doc"
tnorling Jun 22, 2020
5552d53
Revert "Revert VScode settings"
tnorling Jun 22, 2020
d678d50
Revert "Revert VScode settings"
tnorling Jun 22, 2020
30a8394
Revert "Address feedback"
tnorling Jun 22, 2020
c5a88a9
Revert "Address feedback"
tnorling Jun 22, 2020
842a292
Revert "Update untrustedAuthority error message"
tnorling Jun 22, 2020
d89d5c6
Revert "Add error"
tnorling Jun 22, 2020
c326777
Revert "Merge branch 'instance-aware-2.0' of https://github.com/Azure…
tnorling Jun 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"editor.formatOnSave": false,
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
{ "language": "typescript", "autoFix": true }
"typescript"
],
"eslint.quiet": true,
"eslint.workingDirectories": ["./lib/msal-core", "./lib/msal-common", "./lib/msal-browser", "./lib/msal-node", "./lib/msal-angular"],
"files.eol": "\n",
"github-pr.targetBranch": "dev",
"editor.codeActionsOnSave": {
Expand Down
231 changes: 87 additions & 144 deletions lib/msal-browser/src/app/PublicClientApplication.ts

Large diffs are not rendered by default.

29 changes: 11 additions & 18 deletions lib/msal-browser/src/cache/BrowserStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { Constants, PersistentCacheKeys, StringUtils, AuthorizationCodeRequest, ICrypto, CacheSchemaType, AccountEntity, IdTokenEntity, CredentialType, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, CacheManager, CredentialEntity } from "@azure/msal-common";
import { Constants, PersistentCacheKeys, StringUtils, AuthorizationCodeRequest, ICrypto, CacheSchemaType, AccountEntity, IdTokenEntity, CacheHelper, CredentialType, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, CacheManager } from "@azure/msal-common";
import { CacheOptions } from "../config/Configuration";
import { BrowserAuthError } from "../error/BrowserAuthError";
import { BrowserConfigurationAuthError } from "../error/BrowserConfigurationAuthError";
Expand Down Expand Up @@ -144,22 +144,22 @@ export class BrowserStorage extends CacheManager {
switch (type) {
case CacheSchemaType.ACCOUNT: {
const account = new AccountEntity();
return (CacheManager.toObject(account, JSON.parse(value)) as AccountEntity);
return (CacheHelper.toObject(account, JSON.parse(value)) as AccountEntity);
}
case CacheSchemaType.CREDENTIAL: {
const credentialType = CredentialEntity.getCredentialType(key);
const credentialType = CacheHelper.getCredentialType(key);
switch (credentialType) {
case CredentialType.ID_TOKEN: {
const idTokenEntity: IdTokenEntity = new IdTokenEntity();
return (CacheManager.toObject(idTokenEntity, JSON.parse(value)) as IdTokenEntity);
return (CacheHelper.toObject(idTokenEntity, JSON.parse(value)) as IdTokenEntity);
}
case CredentialType.ACCESS_TOKEN: {
const accessTokenEntity: AccessTokenEntity = new AccessTokenEntity();
return (CacheManager.toObject(accessTokenEntity, JSON.parse(value)) as AccessTokenEntity);
return (CacheHelper.toObject(accessTokenEntity, JSON.parse(value)) as AccessTokenEntity);
}
case CredentialType.REFRESH_TOKEN: {
const refreshTokenEntity: RefreshTokenEntity = new RefreshTokenEntity();
return (CacheManager.toObject(refreshTokenEntity, JSON.parse(value)) as RefreshTokenEntity);
return (CacheHelper.toObject(refreshTokenEntity, JSON.parse(value)) as RefreshTokenEntity);
}
}
}
Expand Down Expand Up @@ -343,17 +343,6 @@ export class BrowserStorage extends CacheManager {
this.setItem(this.generateCacheKey(authorityKey), authority, CacheSchemaType.TEMPORARY);
}

/**
* Gets the cached authority based on the cached state. Returns empty if no cached state found.
*/
getCachedAuthority(): string {
const state = this.getItem(this.generateCacheKey(TemporaryCacheKeys.REQUEST_STATE), CacheSchemaType.TEMPORARY) as string;
if (!state) {
return null;
}
return this.getItem(this.generateCacheKey(this.generateAuthorityKey(state)), CacheSchemaType.TEMPORARY) as string;
}

/**
* Updates account, authority, and state in cache
* @param serverAuthenticationRequest
Expand All @@ -378,7 +367,11 @@ export class BrowserStorage extends CacheManager {
// check state and remove associated cache items
this.getKeys().forEach(key => {
if (!StringUtils.isEmpty(state) && key.indexOf(state) !== -1) {
this.removeItem(key);
const splitKey = key.split(Constants.RESOURCE_DELIM);
const keyState = splitKey.length > 1 ? splitKey[splitKey.length-1]: null;
if (keyState === state) {
this.removeItem(key);
}
}
});

Expand Down
4 changes: 3 additions & 1 deletion lib/msal-browser/src/config/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { SystemOptions, LoggerOptions, INetworkModule, LogLevel, DEFAULT_SYSTEM_OPTIONS, Constants } from "@azure/msal-common";
import { SystemOptions, LoggerOptions, INetworkModule, LogLevel, DEFAULT_SYSTEM_OPTIONS, Constants, IInstanceDiscoveryMetadata } from "@azure/msal-common";
import { BrowserUtils } from "../utils/BrowserUtils";
import { BrowserConstants } from "../utils/BrowserConstants";

Expand All @@ -14,6 +14,7 @@ export type BrowserAuthOptions = {
clientId: string;
authority?: string;
knownAuthorities?: Array<string>;
instanceMetadata?: Array<IInstanceDiscoveryMetadata>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming here might get confusing when we implement the other perf changes which introduced authorityMetadata in msal-core. Open to suggestions for a better name here.

redirectUri?: string | (() => string);
postLogoutRedirectUri?: string | (() => string);
navigateToLoginRequestUrl?: boolean;
Expand Down Expand Up @@ -67,6 +68,7 @@ const DEFAULT_AUTH_OPTIONS: BrowserAuthOptions = {
clientId: "",
authority: `${Constants.DEFAULT_AUTHORITY}/`,
knownAuthorities: [],
instanceMetadata: [],
redirectUri: () => BrowserUtils.getCurrentUri(),
postLogoutRedirectUri: () => BrowserUtils.getCurrentUri(),
navigateToLoginRequestUrl: true
Expand Down
24 changes: 0 additions & 24 deletions lib/msal-browser/src/error/BrowserConfigurationAuthError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ import { AuthError } from "@azure/msal-common";
* BrowserAuthErrorMessage class containing string constants used by error codes and messages.
*/
export const BrowserConfigurationAuthErrorMessage = {
redirectUriNotSet: {
code: "redirect_uri_empty",
desc: "A redirect URI is required for all calls, and none has been set."
},
postLogoutUriNotSet: {
code: "post_logout_uri_empty",
desc: "A post logout redirect has not been set."
},
storageNotSupportedError: {
code: "storage_not_supported",
desc: "Given storage configuration option was not supported."
Expand Down Expand Up @@ -44,22 +36,6 @@ export class BrowserConfigurationAuthError extends AuthError {
Object.setPrototypeOf(this, BrowserConfigurationAuthError.prototype);
}

/**
* Creates an error thrown when the redirect uri is empty (not set by caller)
*/
static createRedirectUriEmptyError(): BrowserConfigurationAuthError {
return new BrowserConfigurationAuthError(BrowserConfigurationAuthErrorMessage.redirectUriNotSet.code,
BrowserConfigurationAuthErrorMessage.redirectUriNotSet.desc);
}

/**
* Creates an error thrown when the post-logout redirect uri is empty (not set by caller)
*/
static createPostLogoutRedirectUriEmptyError(): BrowserConfigurationAuthError {
return new BrowserConfigurationAuthError(BrowserConfigurationAuthErrorMessage.postLogoutUriNotSet.code,
BrowserConfigurationAuthErrorMessage.postLogoutUriNotSet.desc);
}

/**
* Creates error thrown when given storage location is not supported.
* @param givenStorageLocation
Expand Down
11 changes: 7 additions & 4 deletions lib/msal-browser/src/interaction_handler/InteractionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { StringUtils, AuthorizationCodeRequest, CacheSchemaType, AuthenticationResult, AuthorizationCodeClient } from "@azure/msal-common";
import { SPAClient, StringUtils, AuthorizationCodeRequest, ProtocolUtils, CacheSchemaType, AuthenticationResult } from "@azure/msal-common";
import { BrowserStorage } from "../cache/BrowserStorage";
import { BrowserAuthError } from "../error/BrowserAuthError";
import { TemporaryCacheKeys } from "../utils/BrowserConstants";
Expand All @@ -12,11 +12,11 @@ import { TemporaryCacheKeys } from "../utils/BrowserConstants";
*/
export abstract class InteractionHandler {

protected authModule: AuthorizationCodeClient;
protected authModule: SPAClient;
protected browserStorage: BrowserStorage;
protected authCodeRequest: AuthorizationCodeRequest;

constructor(authCodeModule: AuthorizationCodeClient, storageImpl: BrowserStorage) {
constructor(authCodeModule: SPAClient, storageImpl: BrowserStorage) {
this.authModule = authCodeModule;
this.browserStorage = storageImpl;
}
Expand Down Expand Up @@ -48,8 +48,11 @@ export abstract class InteractionHandler {
// Assign code to request
this.authCodeRequest.code = authCode;

// Extract user state.
const userState = ProtocolUtils.getUserRequestState(requestState);

// Acquire token with retrieved code.
const tokenResponse = await this.authModule.acquireToken(this.authCodeRequest, cachedNonce, requestState);
const tokenResponse = await this.authModule.acquireToken(this.authCodeRequest, userState, cachedNonce);
this.browserStorage.cleanRequest();
return tokenResponse;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/msal-browser/src/interaction_handler/PopupHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { UrlString, StringUtils, Constants, AuthorizationCodeRequest, CacheSchemaType, AuthorizationCodeClient } from "@azure/msal-common";
import { UrlString, StringUtils, Constants, SPAClient, AuthorizationCodeRequest, CacheSchemaType } from "@azure/msal-common";
import { InteractionHandler } from "./InteractionHandler";
import { BrowserAuthError } from "../error/BrowserAuthError";
import { BrowserConstants } from "../utils/BrowserConstants";
Expand All @@ -16,7 +16,7 @@ export class PopupHandler extends InteractionHandler {

private currentWindow: Window;

constructor(authCodeModule: AuthorizationCodeClient, storageImpl: BrowserStorage) {
constructor(authCodeModule: SPAClient, storageImpl: BrowserStorage) {
super(authCodeModule, storageImpl);

// Properly sets this reference for the unload event.
Expand Down
7 changes: 5 additions & 2 deletions lib/msal-browser/src/interaction_handler/RedirectHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { StringUtils, AuthorizationCodeRequest, ICrypto, CacheSchemaType, AuthenticationResult } from "@azure/msal-common";
import { StringUtils, AuthorizationCodeRequest, ICrypto, ProtocolUtils, CacheSchemaType, AuthenticationResult } from "@azure/msal-common";
import { InteractionHandler } from "./InteractionHandler";
import { BrowserAuthError } from "../error/BrowserAuthError";
import { BrowserConstants, TemporaryCacheKeys } from "../utils/BrowserConstants";
Expand Down Expand Up @@ -68,8 +68,11 @@ export class RedirectHandler extends InteractionHandler {
// Hash was processed successfully - remove from cache
this.browserStorage.removeItem(this.browserStorage.generateCacheKey(TemporaryCacheKeys.URL_HASH));

// Extract user state.
const userState = ProtocolUtils.getUserRequestState(requestState);

// Acquire token with retrieved code.
const tokenResponse = await this.authModule.acquireToken(this.authCodeRequest, cachedNonce, requestState);
const tokenResponse = await this.authModule.acquireToken(this.authCodeRequest, userState, cachedNonce);
this.browserStorage.cleanRequest();
return tokenResponse;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/msal-browser/src/interaction_handler/SilentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { UrlString, StringUtils, AuthorizationCodeRequest, AuthorizationCodeClient } from "@azure/msal-common";
import { UrlString, SPAClient, StringUtils, AuthorizationCodeRequest } from "@azure/msal-common";
import { InteractionHandler } from "./InteractionHandler";
import { BrowserConstants } from "../utils/BrowserConstants";
import { BrowserAuthError } from "../error/BrowserAuthError";
Expand All @@ -11,7 +11,7 @@ import { BrowserStorage } from "../cache/BrowserStorage";
export class SilentHandler extends InteractionHandler {

private loadFrameTimeout: number;
constructor(authCodeModule: AuthorizationCodeClient, storageImpl: BrowserStorage, configuredLoadFrameTimeout: number) {
constructor(authCodeModule: SPAClient, storageImpl: BrowserStorage, configuredLoadFrameTimeout: number) {
super(authCodeModule, storageImpl);
this.loadFrameTimeout = configuredLoadFrameTimeout;
}
Expand Down
Loading