Office-Addin MSAL Single Sign In SSO: How to Refresh the Access Token

Handoo, Rakesh 0 Reputation points
2024-05-01T09:24:01.74+00:00

Hi,

I have developed Office-ExcelAddIn using Angular. I am using OfficeRuntime.auth.getAccessToken() to get the taken for api authentication. After 87min the token expires and ExcelAddIn stops working. If I try to use the getAccessToken() method after 87 minutes, I get an exception.

Even If try to call getAccessToken() before token expiry to refresh the token , I am still getting the exception.

is there a way to refresh the token seamlessly without the user having to close the ExcelAddIn and open again ?

Sample method for getting the token

  public async getUserToken(): Promise<User> {

    try {

      console.log("getUserToken -> Start");

      const tokenData = await OfficeRuntime.auth.getAccessToken({

        allowSignInPrompt: false,

        forMSGraphAccess: true,

      });

      const parts = tokenData.split(".");

      const userToken = JSON.parse(atob(parts[1]));

      this.user = {

        name: userToken.name,

        email: userToken.preferred_username,

        token: tokenData,

      };

    } catch (error: any) {

      console.error(error);

      throw new Error("unable to get token");

    }

    return this._user;

  }

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,570 questions
{count} votes