Adal.js logging out without a redirect

时间秒杀一切 提交于 2019-12-07 12:50:04

问题


In our current SPA implementation we authenticate against AzureAD using adal.js and upon successful authentication hit our web api to get the authorization data. There are a couple of edge case scenarios where the get authorization data call could fail. In this case we would like to clear out the state/cache created by adal.js. I have tried a few things but I have not not been able to create a clean slate. Here is some code that I have tried.

localStorage.clear();
 var authContext = AuthenticationContext.prototype._singletonInstance;
 authContext.clearCache();
 authContext._user = null; 

I don't want to use the built in logout function. Calling logout redirects the user to the Azure signout page. The UX is pretty wierd so trying to avoid it.


回答1:


If you want to clear all the cache entries created by adal, clearCache() is the method that should be used, and if you want to clear the cache only for a specific resource entry, then use clearCacheForResource.

But one more thing to note is, these two methods only clear the cache/storage though, it won't clear any session/cookie hold on azure ad, if you want to clear that, then the built in logout should be the one to use.

You could probably try to implement the silent logout(probably using iframe, this will prevent the ux from displaying), and then call clearCache to clear the localstorage/sessionstorage




回答2:


You can set postLogoutRedirectUri to your aplication setup:

  adalProvider.init(
        {
            instance: 'https://login.microsoftonline.com/',
            tenant: 'www.contoso.com',
            clientId: '0101001010101',
            extraQueryParameter: 'nux=1',
            cacheLocation: 'localStorage', // enable this for IE, as sessionStorage does not work for localhost.
            endpoints: endpoints,
            postLogoutRedirectUri: 'https://www.yourapp.com'
        },
        $httpProvider
        );


来源:https://stackoverflow.com/questions/31708493/adal-js-logging-out-without-a-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!