Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Unable to get accessToken in offline mode returning "null"?

未关闭
#997 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
20/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
azure, javascript, react-native

调研方向

报告没有指出任何仓库文件或测试;请从所示的 getAzureApiAccessConfig 和 getAccessTokenAsync 流程开始,并使用提供的 Azure 授权端点和令牌端点。复现 offline_access 情况,并追踪 null token 是来自库,还是来自应用存储的令牌数据。完成的标准是确定一个可复现的库缺陷,或记录所需的配置更改。

由索引模型根据 Issue 内容生成。

描述

In offline mode, the Access token returns null even added the "offline_access" in the scope

Here the scope

API_ACCESS_SCOPE: [
'offline_access',
'api://xxxxxxxxxxxxxxxxxx/api-access',
],

getAzureApiAccessConfig() {
return {
issuer: ${MS_BASE_API_URL}${TENANT_ID}/v2.0,
clientId: APP_ID,
redirectUrl: REDIRECT_URL,
scopes: API_ACCESS_SCOPE,

  // additionalParameters: {prompt: 'select_account'},
  serviceConfiguration: {
    authorizationEndpoint: `${MS_BASE_API_URL}${TENANT_ID}/oauth2/v2.0/authorize`,
    tokenEndpoint: `${MS_BASE_API_URL}${TENANT_ID}/oauth2/v2.0/token`,
    revocationEndpoint: `${MS_BASE_API_URL}${TENANT_ID}/oauth2/v2.0/logout`,
  },
};

}

async getAccessTokenAsync() {
try {
const userInfo = await this.getUserInfo();

  const expireTime = userInfo.apiAccessTokens
    ? userInfo.apiAccessTokens.expiryTime
    : null;

  console.log('expireTime :>> ', expireTime);

  if (expireTime !== null) {
    // Get expiration time - 5 minutes

    // If it's <= 5 minutes before expiration, then refresh

    const expire = sub(parseISO(expireTime), {minutes: 5});

    const now = new Date();

    console.log(
      'Expire comparison :>> ',

      expire,

      now,

      compareAsc(now, expire),
    );

    if (compareAsc(now, expire) >= 0) {
      // Expired, refresh

      console.log('Refreshing token');

      const refreshToken = userInfo.apiAccessTokens
        ? userInfo.apiAccessTokens.refreshToken
        : null;

      console.log(`Refresh token: ${refreshToken}`);

      const result = await refresh(this.getAzureApiAccessConfig(), {
        refreshToken: refreshToken || '',
      });

      if (!result?.accessToken) {
        await this.logOut();

        return null;
      }

      // Store the new access token, refresh token, and expiration time in storage

      await SECURE_STORAGE.saveData(KEY_AUTH_USER_INFO, {
        ...userInfo,

        apiAccessTokens: {
          accessToken: result.accessToken,

          refreshToken: result.refreshToken ?? '',

          expiryTime: result.accessTokenExpirationDate,
        },
      });

      return result.accessToken;
    }

    // Not expired, just return saved access token

    const accessToken = userInfo.apiAccessTokens
      ? userInfo.apiAccessTokens.accessToken
      : null;

    return accessToken;
  }

  return null;
} catch (error) {
  console.log('error while fetching access token :>> ', error);

  await this.logOut();

  return null;
}

}

please help me what's went wrong?

主要语言
Java
星标
2.3k
派生
471
平均合并
3 天 7 小时
30 天内合并 PR
3

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

FormidableLabs/react-native-app-auth 的其他 Issue

查看 FormidableLabs/react-native-app-auth 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。