最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Adal.js logging out without a redirect - Stack Overflow

programmeradmin0浏览0评论

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.

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.

Share Improve this question asked Jul 29, 2015 at 18:33 kolhapurikolhapuri 1,6514 gold badges21 silver badges32 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

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

You can set postLogoutRedirectUri to your aplication setup:

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

评论列表(0)

  1. 暂无评论