Reactjs I';我使用react adal进行Azure AD单点登录。它';s令牌在1小时后过期。有没有办法刷新会话或延长会话到期时间

Reactjs I';我使用react adal进行Azure AD单点登录。它';s令牌在1小时后过期。有没有办法刷新会话或延长会话到期时间,reactjs,azure,azure-active-directory,adal,adal.js,Reactjs,Azure,Azure Active Directory,Adal,Adal.js,我已使用Azure AD单点登录库将Azure AD单点登录集成到我的公司react应用程序中。我已经成功地实现了它,但我面临一个问题。它的令牌将在1小时后过期,因为它将从react web应用程序中注销。是否有任何方法刷新会话或延长会话到期时间 import { AuthenticationContext } from 'react-adal'; const config = { apiUrl: 'someUrl/', graph_access_url: 'https://graph

我已使用Azure AD单点登录库将Azure AD单点登录集成到我的公司react应用程序中。我已经成功地实现了它,但我面临一个问题。它的令牌将在1小时后过期,因为它将从react web应用程序中注销。是否有任何方法刷新会话或延长会话到期时间

import { AuthenticationContext } from 'react-adal';

const config = {
  apiUrl: 'someUrl/',
  graph_access_url: 'https://graph.microsoft.com',
  graph_access_token_key: 'User_Graph_Token',
  user_info_key: 'UserInfo'
};

const adalConfig = {
  tenant: 'someTenant',
  clientId: 'someclientId',
  clientSecret: 'someclientSecret',
  objectId: 'someObjectId',
  endpoints: { api: 'someAPI' },
  cacheLocation: 'localStorage',
  redirectUri: window.location.origin,
  azureRootUrl: 'https://login.microsoftonline.com',
  issuerUrl: 'https://sts.windows.net'
};

const authContext = new AuthenticationContext(adalConfig);

function graphAccessToken() {
  return localStorage[config.graph_access_token_key];
}

function azureRequest(url) {
  let token = graphAccessToken();
  const requestOptions = { method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: 'Bearer ' + token } };
  return fetch(url, requestOptions).then(response => response.json());
}

function getMe() {
  return azureRequest('https://graph.microsoft.com/v1.0/me');
}

function login() {
  authContext.login();
}

export function logout() {
  localStorage.setItem(config.user_info_key, '');
  localStorage.setItem(config.graph_access_token_key, '');
  localStorage.clear();
  authContext.logOut();
}

authContext.handleWindowCallback();

if (window === window.parent) {
  if (!authContext.isCallback(window.location.hash)) {
    if (authContext.getCachedToken(authContext.config.clientId) || authContext.getCachedUser()) {
      authContext.acquireToken('https://graph.microsoft.com', (error, id_token) => {
        if (id_token) {
          localStorage.setItem(config.graph_access_token_key, id_token);
          if (localStorage.getItem('adal.idtoken')) {
            // Some Logic Implemented here.
          }
        }
      });
    }
  }
}


react adal
使用iframe进行令牌静默刷新,您需要使用
index.js
,如下所示

您生成的第一个令牌的生命周期为1小时,当该令牌即将到期时,库将检索一个刷新令牌。默认情况下,此库将在当前令牌过期日期前至少5分钟尝试刷新令牌

index.js

import { runWithAdal } from 'react-adal';
import { authContext } from './adalConfig';
 
const DO_NOT_LOGIN = false;
 
runWithAdal(authContext, () => {
 
  require('./indexApp.js');
 
},DO_NOT_LOGIN);
有关详细信息,请参见的前端部分