Udostępnij za pośrednictwem


Clearing authentication cookie when developing with multiple Office365 tenants

This is just a quick productivity tip when you are developing with multiple tenants in Office365. In my case I have many difference development tenants and our company obviously is using Office365, which adds some of the burden with the movement cross tenants. If you intentionally or by accident save the credentials with the tenants that you use in daily work, you will run into one of the followings when you try to access different tenant.

image

This is caused due the fact that my login information has been saved with different tenant information and I can’t get to another. Currently we cannot share identities cross multiple tenants, so you’ll have sign out from tenant and re-login for the new one. Due miscellaneous reasons the “click here to sign in with different account to this site” might not work and then you end up in nice loop of trying to get rid of the login information.

There is good Microsoft Knowledge Base article explaining the options, but clearing for example all the cached files does not really seem nice. Alternative for signing out is also to always play with In-private modes or with multiple browsers, which as definitely also valid options, and you can choose the preferred model for you. Clearing the cookies works pretty nicely at least for me.

 

PowerShell to clear Office365 and Yammer cookies

Here’s a quick helper PowerShell scripts I wrote for clearing my cookies when needed. I actually wrote a separate one for Yammer cookies, but you could combine them pretty easily. These are for Windows 8.1, but they should be looking pretty similar if you are using some other OS in your development lap top.

Clear Office365 cookies from the cookie store

# DELETE Office365 cookies
([system.environment]::GetFolderPath('Cookies')) | Get-ChildItem -recurse | Select-String -pattern "microsoftonline" | group path | ForEach-Object { Remove-Item $_.name }
([system.environment]::GetFolderPath('Cookies')) | Get-ChildItem -recurse | Select-String -pattern "sharepoint.com" | group path | ForEach-Object { Remove-Item $_.name }

Clear Yammer cookies from the cookie store

 # DELETE YAMMER cookies
([system.environment]::GetFolderPath('Cookies')) | Get-ChildItem -recurse | Select-String -pattern "yammer" | group path | ForEach-Object { Remove-Item $_.name }

 

Placing scripts to easily executable location

Depending how often you’d need the scripts, you most likely want to place them to some easily accessible location. In my case I created batch files for the PowerShell execution and added new toolbar to the task bar, so that I can now easily select which script I want to execute directly from the task bar.

image

Summary

PowerShell to the rescue and for automating the authentication cookie clearing. So now whenever I get the authentication issues, I perform following actions:

  1. Close browser
  2. Execute the needed clear cookie batch script
  3. Reopen the browser
    • This could be included to the script as well

That was a quick and small productivity tip based on the questions I’ve got lately related on Office365 development. Hopefully that was useful. If you have good other tips, don’t hesitate to comment and share.

Comments

  • Anonymous
    June 16, 2014
    Very useful post Vesa - you have no idea what a pain this has been recently with 'super' sticky cookie sessions!

  • Anonymous
    June 16, 2014
    How about just running IE using "In Private Browsing" ? It automatically clears all cookies and temporarily cached files from the session, and also doesn't remove any cookies you might want to keep in your "normal" browser sessions.

  • Anonymous
    June 16, 2014
    Hi Martin. Like mentioned in the post, that's completely fine option as well. Only downside is that you can't make Visual Studio to run debugging in In-Private mode, but other than that, it is perfectly fine option as well. "Alternative for signing out is also to always play with In-private modes or with multiple browsers, which as definitely also valid options, and you can choose the preferred model for you. Clearing the cookies works pretty nicely at least for me."

  • Anonymous
    June 18, 2014
    This is gold!  Thanks Vesa

  • Anonymous
    August 21, 2014
    For chrome users, all you need is to setup multiple profile directories in settings page. One of my customers uses Chrome heavily and this trick works well there, enabling people to save passwords in multiple tenants without losing cookies.