Skip to content
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

Missed state when create a new UserAgentApplication #778

Closed
5 tasks
dluque92 opened this issue Jun 21, 2019 · 11 comments
Closed
5 tasks

Missed state when create a new UserAgentApplication #778

dluque92 opened this issue Jun 21, 2019 · 11 comments
Labels
question Customer is asking for a clarification, use case or information.

Comments

@dluque92
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:

Browser:

  • Chrome version XX
  • Firefox version XX
  • IE version XX
  • Edge version XX
  • Safari version XX

Library version


Library version: 1.0.2



## Current behavior

In Configuration.ts we have the following lines to describe and define AuthOptions:

/**
 * @type AuthOptions: Use this to configure the auth options in the Configuration object
 *
 *  - clientId                    - Client ID of your app registered with our Application registration portal : https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview in Microsoft Identity Platform
 *  - authority                   - You can configure a specific authority, defaults to " " or "https://login.microsoftonline.com/common"
 *  - validateAuthority           - Used to turn authority validation on/off. When set to true (default), MSAL will compare the application's authority against well-known URLs templates representing well-formed authorities. It is useful when the authority is obtained at run time to prevent MSAL from displaying authentication prompts from malicious pages.
 *  - redirectUri                 - The redirect URI of the application, this should be same as the value in the application registration portal.Defaults to `window.location.href`.
 *  - postLogoutRedirectUri       - Used to redirect the user to this location after logout. Defaults to `window.location.href`.
 *  - state                       - Use to send the state parameter with authentication request
 *  - navigateToLoginRequestUrl   - Used to turn off default navigation to start page after login. Default is true. This is used only for redirect flows.
 *
 */
export type AuthOptions = {
  clientId: string;
  authority?: string;
  validateAuthority?: boolean;
  redirectUri?: string | (() => string);
  postLogoutRedirectUri?: string | (() => string);
  navigateToLoginRequestUrl?: boolean;
};

## Expected behavior

As you can see in the comments below, is an state propertie, that is missing in the type AuthOptions


## Minimal reproduction of the problem with instructions



If is not included since new versions, how can I manage it, and pass state? I need it to control state after callback in SignIn or EditProfile policies

@pkanher617
Copy link
Contributor

pkanher617 commented Jun 21, 2019

Hi @dluque92, we allow the user to pass a state in the AuthenticationParameters object, which is the object sent in the login and acquireToken requests.

/**
 * @link AuthenticationParameters}AuthenticationParameters
 */
export type AuthenticationParameters = {
    scopes?: Array<string>;
    extraScopesToConsent?: Array<string>;
    prompt?: string;
    extraQueryParameters?: QPDict;
    claimsRequest?: string;
    authority?: string;
    state?: string;
    correlationId?: string;
    account?: Account;
    sid?: string;
    loginHint?: string;
};

Example:

let loginRequest = {
   state = "1234"
};

loginPopup(loginRequest).then(loginResponse => {
   let responseState = loginResponse.accountState;
}).catch(error => {
   console.log(error);
});

This pattern should be the same for all of the login and acquiretoken APIs. Please let me know if you are still having issues.

@yakimko
Copy link

yakimko commented Jun 21, 2019

@pkanher617 I got tslint error when try to pass state property, because its not defined in type

@pkanher617
Copy link
Contributor

Hm I haven't received this error before. Could you post a code snippet of your acquireToken or login call and the request object you are constructing?

@dluque92
Copy link
Author

Hi @pkanher617 the new UserAgentApplication expects config with this format:
https://docs.microsoft.com/bs-latn-ba/azure/active-directory/develop/msal-js-initializing-client-applications


export type Configuration = {
    auth: AuthOptions,
    cache?: CacheOptions,
    system?: SystemOptions,
    framework?: FrameworkOptions
};

@pkanher617
Copy link
Contributor

@dluque92 As of MSAL.js v1.0.0, we no longer accept state as a configuration parameter. This is because the state needs to be set per request, not per instance of MSAL.

The new configuration objects and parameters can be found here.

We have also changed how the requests for login and acquireToken are made. A new object called AuthenticationParameters is now used to pass state.

@sameerag
Copy link
Member

@dluque92 To expand specifically how a request looks:

export type AuthenticationParameters = {
scopes?: Array;
extraScopesToConsent?: Array;
prompt?: string;
extraQueryParameters?: Dict;
claimsRequest?: string;
authority?: string;
state?: string;
correlationId?: string;
account?: Account;
sid?: string;
loginHint?: string;
};

We will be sticking to this more or less(except may be adding some more params if there is a user need). Please check the 1.0.0 announcement for more details.

@dluque92
Copy link
Author

@sameerag Then this file is wrong:
https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/bff2b7007bfa7283fe8b9b77ca95994e5cef5c97/lib/msal-core/src/Configuration.ts

/**
 * @type AuthOptions: Use this to configure the auth options in the Configuration object
 *
 *  - clientId                    - Client ID of your app registered with our Application registration portal : https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview in Microsoft Identity Platform
 *  - authority                   - You can configure a specific authority, defaults to " " or "https://login.microsoftonline.com/common"
 *  - validateAuthority           - Used to turn authority validation on/off. When set to true (default), MSAL will compare the application's authority against well-known URLs templates representing well-formed authorities. It is useful when the authority is obtained at run time to prevent MSAL from displaying authentication prompts from malicious pages.
 *  - redirectUri                 - The redirect URI of the application, this should be same as the value in the application registration portal.Defaults to `window.location.href`.
 *  - postLogoutRedirectUri       - Used to redirect the user to this location after logout. Defaults to `window.location.href`.
 *  - state                       - Use to send the state parameter with authentication request
 *  - navigateToLoginRequestUrl   - Used to turn off default navigation to start page after login. Default is true. This is used only for redirect flows.
 *
 */
export type AuthOptions = {
  clientId: string;
  authority?: string;
  validateAuthority?: boolean;
  redirectUri?: string | (() => string);
  postLogoutRedirectUri?: string | (() => string);
  navigateToLoginRequestUrl?: boolean;
};

@pkanher617
Copy link
Contributor

@dluque92 Thanks for pointing that out. I will fix the comments right now.

@dluque92
Copy link
Author

dluque92 commented Jun 21, 2019

@pkanher617 But also, the AuthenticationParameters has been changed, As you said here

How can we pass state in this case?
Thanks!

type storage = "localStorage" | "sessionStorage";

// Protocol Support
export type AuthOptions = {
    clientId: string;
    authority?: string;
    validateAuthority?: boolean;
    redirectUri?: string | (() => string);
    postLogoutRedirectUri?: string | (() => string);
    navigateToLoginRequestUrl?: boolean;
};

// Cache Support
export type CacheOptions = {
    cacheLocation?: CacheLocation;
    storeAuthStateInCookie?: boolean;
};

// Library support
export type SystemOptions = {
    logger?: Logger;
    loadFrameTimeout?: number;
    tokenRenewalOffsetSeconds?: number;
};

// Developer App Environment Support
export type FrameworkOptions = {
    isAngular?: boolean;
    unprotectedResources?: Array<string>;
    protectedResourceMap?: Map<string, Array<string>>;
};

// Configuration Object
export type Configuration = {
    auth: AuthOptions,
    cache?: CacheOptions,
    system?: SystemOptions,
    framework?: FrameworkOptions
};

@pkanher617
Copy link
Contributor

@dluque92 This is still the configuration object.

Please see my above comment and the AuthenticationParameters.ts class.

@DarylThayil DarylThayil added question Customer is asking for a clarification, use case or information. updatedocs labels Jun 21, 2019
@sameerag
Copy link
Member

@dluque92 as @pkanher617 mentioned above, AuthenticationParameters.ts class has the detail on how to send the 'state' per request. Closing this issue as #780 is in dev.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Customer is asking for a clarification, use case or information.
Projects
None yet
Development

No branches or pull requests

5 participants