Skip to content

Rohitnarula7176/token cache #1

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

Merged
merged 1 commit into from
Mar 29, 2017
Merged

Conversation

rohitnarula7176
Copy link
Contributor

No description provided.

@msftclas
Copy link

@rohitnarula7176,
Thanks for your contribution as a Microsoft full-time employee or intern. You do not need to sign a CLA.
Thanks,
Microsoft Pull Request Bot

lib/msaljs.ts Outdated
}

export class Constants {
public static get ERROR_DESCRIPTION(): string { return "error_description"; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check the naming conventions for constants in TS. I don't think we should use "_".

lib/msaljs.ts Outdated
export class Constants {
public static get ERROR_DESCRIPTION(): string { return "error_description"; }
public static get ID_TOKEN(): string { return "id_token"; }
public static get ACCESS_TOKEN(): string { return "access_token"; }
Copy link
Contributor

Choose a reason for hiding this comment

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

I think all of these should be private except loadframe timeout and popup width and height.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, see if using readonly attribute makes more sense. That way, you can define these as properties instead of methods.

static readonly AccessToken: string = "access_token"

lib/msaljs.ts Outdated
export class ClientApplication {

private loginInProgress: boolean;
User: User;
Copy link
Contributor

Choose a reason for hiding this comment

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

I should have checked this earlier. Guideline is to use camelcase for method and property names. https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines

lib/msaljs.ts Outdated
public static get UNKNOWN(): string { return "UNKNOWN"; }
}

export class ClientApplication {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename this to UserAgentApplication.

lib/msaljs.ts Outdated
private loginInProgress: boolean;
User: User;
ClientId: string;
Authority: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be readonly

lib/msaljs.ts Outdated
Authority: string;
AuthenticationMode: AuthenticationModes;
RedirectUri: string;
ClockSkew: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be private, default to 5 minutes

lib/msaljs.ts Outdated
ActiveRenewals: Object;
SessionState: string;
CacheStorage: Storage;

Copy link
Contributor

Choose a reason for hiding this comment

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

Add ValidateAuthority boolean property to turn on/off authority validation. Default should be true but I think until build, default is false.

lib/msaljs.ts Outdated
User: User;
ClientId: string;
Authority: string;
AuthenticationMode: AuthenticationModes;
Copy link
Contributor

Choose a reason for hiding this comment

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

There was a suggestion to reword this to something else maybe InteractionMode.

lib/msaljs.ts Outdated
RedirectUri: string;
ClockSkew: number;
PostLogoutRedirectUri: string;
CorrelationId: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure where we landed on this one. Should it be here or at acquireToken level only. Check what other MSALs have landed upon.

lib/msaljs.ts Outdated
CorrelationId: string;
CacheLocation: CacheLocations;
CheckSessionIframe: HTMLIFrameElement;
RenewStates: Array<string>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Private

lib/msaljs.ts Outdated
CacheLocation: CacheLocations;
CheckSessionIframe: HTMLIFrameElement;
RenewStates: Array<string>;
ActiveRenewals: Object;
Copy link
Contributor

Choose a reason for hiding this comment

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

Private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

lib/msaljs.ts Outdated
CheckSessionIframe: HTMLIFrameElement;
RenewStates: Array<string>;
ActiveRenewals: Object;
SessionState: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

lib/msaljs.ts Outdated
PostLogoutRedirectUri: string;
CorrelationId: string;
CacheLocation: CacheLocations;
CheckSessionIframe: HTMLIFrameElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this used for? Should this be public or private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

private

lib/msaljs.ts Outdated
this.CacheStorage = new Storage(this.CacheLocation);
}

Login(scopes: Array<string>): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

camelCasing for method names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

lib/msaljs.ts Outdated
constructor(clientId: string) {
this.ClientId = clientId;
this.Authority = "https://login.microsoftonline.com/common";
this.RedirectUri = window.location.href;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should process the redirect uri to remove query parameters and hashes, the way we do it in adal.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

lib/msaljs.ts Outdated
RenewStates: Array<string>;
ActiveRenewals: Object;
SessionState: string;
CacheStorage: Storage;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

lib/msaljs.ts Outdated
3. redirect user to AAD
*/

let parameters: AuthenticationRequestParameters = new AuthenticationRequestParameters(this.Authority, this.ClientId, this.AuthenticationMode, null, ResponseTypes[ResponseTypes.id_token], this.RedirectUri);
Copy link
Contributor

Choose a reason for hiding this comment

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

can we please rename this to "request" or "authenticationRequest"? I named it parameters earlier, that does not look like an apt name now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

lib/msaljs.ts Outdated
console.log(urlNavigate);
this.loginInProgress = true;
if (this.AuthenticationMode == AuthenticationModes.PopUp) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need to be implemented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it still needs to be implemented

lib/msaljs.ts Outdated
window.callBackMappedToRenewStates[expectedState] = function (message: string, token: string) {
self.ActiveRenewals[resource] = null;
for (var i = 0; i < window.callBacksMappedToRenewStates[expectedState].length; ++i) {
window.callBacksMappedToRenewStates[expectedState][i](message, token);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add a try catch around this call and reset the window properties even when the exception occurs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we are not relying on user provided callback methods and using promises instead, we don't need to worry about the case in which their code throws an error and we stop execution.

lib/msaljs.ts Outdated
}

private getCachedToken(scopes: Array<string>): string {
let accessTokenCacheItems = this.CacheStorage.getAllAccessTokens(this.ClientId, this.Authority);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should pass user if also in the method since we are filtering the tokens based on that afterwards.

lib/msaljs.ts Outdated
private getCachedToken(scopes: Array<string>): string {
let accessTokenCacheItems = this.CacheStorage.getAllAccessTokens(this.ClientId, this.Authority);
let accessTokenItems: Array<AccessTokenCacheItem> = []; // Array to store multiple accessTokens for the ssame set of scopes
if (accessTokenCacheItems.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need this check if acquireToken is called without logging in or app reload.

lib/msaljs.ts Outdated
}
}
}
if (accessTokenItems.length == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we combine the two statements (== 0) and (> 1) in one if block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

lib/msaljs.ts Outdated

private getCachedToken(scopes: Array<string>): string {
let accessTokenCacheItems = this.CacheStorage.getAllAccessTokens(this.ClientId, this.Authority);
let accessTokenItems: Array<AccessTokenCacheItem> = []; // Array to store multiple accessTokens for the ssame set of scopes
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be an array? Since more than 1 matching tokens is not supported, I think this can be just a variable. Starting value can be null. In line 230, we can check if the variable is not null before assigning. If so, we return null there, otherwise continue. Line 235 check can be changed to check if variable is null.

It's just defining it as an array when we only expect one value does not seem right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can get multiple access tokens for the same set of scopes so we need an array to store them. But in the case we get more than one access token we return null from this method.

Copy link
Contributor

@tushargupta51 tushargupta51 Mar 24, 2017

Choose a reason for hiding this comment

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

As we discussed, lets change that to single object.

lib/msaljs.ts Outdated

AcquireToken(scopes: Array<string>, callback: Function): void;

AcquireToken(scopes: Array<string>, callback: Function, loginHint: string): void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add one more override that has the below signature

AcquireToken(scopes: Array, callback: Function, loginHint: string, extraQueryParameters: string)): void;

lib/msaljs.ts Outdated
this.registerCallback(this.ActiveRenewals[scope], scope, callback);
}
else {
let parameters: AuthenticationRequestParameters = new AuthenticationRequestParameters(this.Authority, this.ClientId, this.AuthenticationMode, null, ResponseTypes[ResponseTypes.token], this.RedirectUri);
Copy link
Contributor

Choose a reason for hiding this comment

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

please rename this to "request" or "authenticationRequest" or "tokenRequest"

lib/msaljs.ts Outdated
else {
let parameters: AuthenticationRequestParameters = new AuthenticationRequestParameters(this.Authority, this.ClientId, this.AuthenticationMode, null, ResponseTypes[ResponseTypes.token], this.RedirectUri);
let expectedState = parameters.State + '|' + scope;
this.CacheStorage.saveItem(Constants.NONCE_IDTOKEN, parameters.Nonce);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to save the nonce for accessToken request.

lib/msaljs.ts Outdated
if (popupWindow == null) {
return;
}
if (this.RedirectUri.indexOf('#') != -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be handled in the constructor.

lib/msaljs.ts Outdated
var frameHandle = self.addAdalFrame(frameCheck);
if (frameHandle.src === '' || frameHandle.src === 'about:blank') {
frameHandle.src = urlNavigate;
self.loadFrame(urlNavigate, frameCheck);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we change this recursive call behavior now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure about what benefit we get from this check. I would want to keep this there as it has not caused any problems in Adaljs.

Copy link
Contributor

Choose a reason for hiding this comment

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

As we discussed, it might be useful to get rid of this now instead of taking it along in msal

@rohitnarula7176 rohitnarula7176 requested a review from weijjia March 28, 2017 00:10
@brentschmaltz brentschmaltz force-pushed the rohitnarula7176/tokenCache branch from 9b99c03 to 76eb5b3 Compare March 29, 2017 18:13
@brentschmaltz brentschmaltz merged commit 76eb5b3 into dev Mar 29, 2017
@rohitnarula7176 rohitnarula7176 deleted the rohitnarula7176/tokenCache branch April 4, 2017 01:24
denyo pushed a commit to denyo/microsoft-authentication-library-for-js that referenced this pull request Sep 15, 2017
Add typings field in package.json to expose msal.d.ts
@roneesh roneesh mentioned this pull request Apr 2, 2020
5 tasks
pkanher617 pushed a commit that referenced this pull request Jun 17, 2020
[msal-node][#1] SilentFlow support in msal-common
@sameerag sameerag mentioned this pull request Jun 24, 2020
1 task
sameerag added a commit that referenced this pull request Jul 13, 2020
tnorling added a commit that referenced this pull request Aug 3, 2020
pkanher617 pushed a commit that referenced this pull request Aug 20, 2020
AT Proof-Of-Possession #1: Adding req_cnf to the token request
pkanher617 pushed a commit that referenced this pull request Aug 26, 2020
Broker #1: Handshake between child and parent
tnorling added a commit that referenced this pull request Oct 19, 2020
tnorling added a commit that referenced this pull request Apr 5, 2021
hectormmg added a commit that referenced this pull request Jan 28, 2022
* Add KeyManager class

* Add STK JWK to BaseAuthRequest

* Add STK generation logic to common and browser

* Update PublicClientApplication tests to mock out STK generation from Auth Code requests

* Undo msal-node-samples changes

* Move generateCnf from PopTokenGenerator to KeyManager

* Refactor crypto key generation to use different key generation algorithm options for AT and RT PoP

* Add missing API from Crypto Interface to msal-node

* Fix linter issues

* Fix merge conflicts

* Refactor Cryptographic constants out of BrowserConstants and CryptoOps

* Fix tests after merge

* Add feature flag to make RT Binding opt-in

* Add error handling to STK generation step

* Refactor crypto enum names

* Add error handling for crypto key generation

* Put KeyManager instance in BaseClient instead of AuthCode and Refresh Clients

* Fix import in BaseClient

* Extend KeyManager tests

* Increase test coverage

* Update lib/msal-browser/src/utils/CryptoConstants.ts

* Update lib/msal-common/test/client/RefreshTokenClient.spec.ts

Co-authored-by: Thomas Norling <[email protected]>

* Fix incorrect typing and checks for private key on getPublicKeyThumbprint

* Refactor cryptographic constants to have more consistent casing

* Fix CryptoOps tests around getPublicKeyThumbprint

* Move refreshTokenBinding feature flag to system config

* Update browser client config to move refreshTokenBinding flag to system config

* Rename KeyManager to CryptoKeyManager for more specificity

* Update BrowserAuthError to remove keyId from error message and avoid Pii

* Update lib/msal-browser/src/config/Configuration.ts

* Refactor CryptoKeyManager into PopTokenGenerator

* Change files

* Replace crypto key type switch in getPublicKeyThumbprint with a ternary assignment

Co-authored-by: Jason Nutter <[email protected]>

* Update changefiles

* Extend CryptoOps logging

* Update exception handling and logging in CryptoOps getPublicKeyThumbprint API

* Fix failing test in CryptoOps spec

Co-authored-by: Thomas Norling <[email protected]>
Co-authored-by: Sameera Gajjarapu <[email protected]>
Co-authored-by: Jason Nutter <[email protected]>
tnorling added a commit that referenced this pull request Mar 12, 2025
Making request generation more flexible in preparation for upcoming EAR
protocol support.
jo-arroyo added a commit that referenced this pull request Apr 16, 2025
This PR updates the BrowserAuthOptions for MSAL Browser v5, including:
- Removal of references, implementations, and tests for
`skipAuthorityMetadataCache`
- Moves `protocolMode` to SystemOptions
- Removal of documentation references to `supportsNestedAppAuth`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants