FormidableLabs / FormidableLabs/react-native-app-auth
Unable to get accessToken in offline mode returning "null"?
- Ngôn ngữ chính
- Java
- Star
- 2.3k
- Fork
- 473
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
## 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?
Hướng dẫn đóng góp
Hướng nghiên cứu
Báo cáo không nêu tệp nào trong repository hay bài kiểm thử nào; hãy bắt đầu từ luồng getAzureApiAccessConfig và getAccessTokenAsync được nêu, sử dụng các endpoint cấp quyền và token Azure đã cung cấp. Tái hiện trường hợp offline_access và truy vết xem token null đến từ thư viện hay từ dữ liệu token được ứng dụng lưu trữ. Hoàn tất nghĩa là xác định được lỗi thư viện có thể tái hiện hoặc ghi lại thay đổi cấu hình cần thiết.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- azure, javascript, react-native
- Lĩnh vực
- authentication, mobile
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 20/100