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

Redirect user to a specific Uri instead of previous window location #238

Closed
brianharwell opened this issue Jan 30, 2018 · 10 comments
Closed
Assignees
Labels
enhancement Enhancement to an existing feature or behavior.

Comments

@brianharwell
Copy link

brianharwell commented Jan 30, 2018

When I redirect a user to the sign in page at Microsoft the user is redirected back to the page they were on when they were redirected and not the redirect uri that I specified.

@rohitnarula7176
Copy link
Contributor

@brianharwell The redirectUri is just used to add to the authorization request. By design, Msal tries to take you back to the page where you started from when you clicked login to start the authentication process.

@rohitnarula7176 rohitnarula7176 self-assigned this Jan 31, 2018
@brianharwell
Copy link
Author

But why? The idea with redirect uri is to tell the browser where to go after the user authenticates with the identity provider, is it not? I have not tried cookie authentication but I remember this being the case in the demos I have watched. I have a use case for wanting the user redirected to a different page than their initial launch point and it seems odd that msal would completely ignore this.

@spottedmahn
Copy link
Contributor

Yes, please allow us to control if we want this behaior

private handleAuthenticationResponse(hash: string): void {

        ...

	if (window.parent === window && !isPopup && [I_WANT_THIS_TO_HAPPEN]) {
		window.location.href = self._cacheStorage.getItem(Constants.loginRequest);
	}
}

@brianharwell
Copy link
Author

I'll take a look this weekend and see if I can create a pull request

@spottedmahn
Copy link
Contributor

Hi @brianharwell - I would wait for their response first. You might end up wasting your time 😞

@brianharwell
Copy link
Author

The constructor for UserAgentApplication takes in an options object. There is a redirectUri property and a postLogoutRedirectUri property. If you do not set them the default is to use the current url. If you do set either of them then the user will be redirected to the specified url after the redirection from Microsoft.

@navyasric navyasric added the enhancement Enhancement to an existing feature or behavior. label Feb 6, 2018
@navyasric navyasric changed the title RedirectUri is not honored Redirect user to a specific Uri instead of previous window location Feb 7, 2018
@hakimio
Copy link

hakimio commented Feb 12, 2018

By design, Msal tries to take you back to the page where you started from when you clicked login to start the authentication process.

@rohitnarula7176 This undocumented behavior doesn't make any sense and is a bug.

@spottedmahn
Copy link
Contributor

Hi @hakimio - for some people, it's probably a nice feature but for others, it is not. We, as the consumers of the library, should be able to choose IMHO.

It should definitely be documented though, as you stated.

@rohitnarula7176
Copy link
Contributor

@spottedmahn @hakimio @brianharwell You can now pass navigateToLoginRequestUrl:false as follows:

        var userAgentApplication = new Msal.UserAgentApplication(applicationConfig.clientID, null, authCallback, { navigateToLoginRequestUrl:false });

In this case , Msal will set the hash to '' and call your callback where you can perform your custom navigation.

Along with this change, there is one more thing that will be part of our next release. We have made the constructor function synchronous.

So to access an instance of userAgentApplication in your callback , you will need to use "this" in the function scope as the control to the constructor is returned after calling your callback.

 var userAgentApplication = new Msal.UserAgentApplication(applicationConfig.clientID, null, authCallback);
        function authCallback(errorDesc, token, error, tokenType) {
                   console.log(userAgentApplication) //this will print undefined, use this instead
                    var self  = this// self is instance of userAgentApplication
           }

Can you please test the change using the dev branch and confirm if it works for you.

@SushanthYethonda
Copy link

SushanthYethonda commented Feb 5, 2019

Hi @rohitnarula7176 ,

#238 (comment)

i followed this and i have not given redirectUri property value

//Factory method

var storeLatestTokenInLocalStorage = function(){
var defered =  $q.defer();
userAgentApplication.acquireTokenSilent(['user.read files.read files.readwrite'], '', '', {navigateToLoginRequestUrl:false}).then(function (accessToken) {                    
        //AcquireTokenSilent Success
        window.localStorage.setItem("tokenBizAzureApp", accessToken); 
       defered.resolve(true);
},function(error){
      defered.reject(false);
});
};

//Controller method
$scope.ajaxcall.promise.then(function () {
            console.log('ggggg');
        });
//
$scope.CheckTokenExist = function(){
       factory.storeLatestTokenInLocalStorage().then(function(response){
            //Doing something after latest token appears in localstorage
           if(response){
              ........
           }
      });
};

acquireTokenSilent it is loading whole page silently instead where it is called like $scope.CheckTokenExist, is it possible to redirect previous function only where it is called.

@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
enhancement Enhancement to an existing feature or behavior.
Projects
None yet
Development

No branches or pull requests

6 participants