npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hxa-rn/react-native-app-auth

v8.1.0-beta.1

Published

React Native bridge for AppAuth for supporting any OAuth 2 provider

Readme

本项目基于 react-native-app-auth开发。如果在使用过程中有任何问题,欢迎在AtomGit提交Issue,会及时跟进。

项目介绍

@hxa-rn/react-native-app-auth 为 React Native 库 react-native-app-auth 的鸿蒙适配包,提供 OAuth 2.0 / OpenID Connect 授权码流程(含 PKCE)、配置预取、令牌刷新、动态客户端注册、令牌吊销与会话登出。当前版本 8.1.0-beta.1,对应上游 8.1.0,支持 Autolink,编译目标 API 12+。

集成指南

npm install @hxa-rn/react-native-app-auth

peerDependencies:react-native >= 0.72。

包内已声明 harmony.alias 为 react-native-app-auth。业务代码在配置 alias 后仍从原库名导入:

import { authorize, prefetchConfiguration, refresh } from 'react-native-app-auth';

不要写成 from '@hxa-rn/react-native-app-auth'。

当前版本支持 Autolink;工程已接入时可跳过手动配置。如需 Manual Link:

  1. 在工程根 oh-package.json5 配置 @rnoh/react-native-openharmony 的 overrides(按宿主工程约定)。
  2. 在 entry/oh-package.json5 添加依赖:"@hxa-rn/react-native-app-auth": "file:../../node_modules/@hxa-rn/react-native-app-auth/harmony/rnaa.har",并执行 ohpm install。
  3. 在 entry/src/main/cpp/CMakeLists.txt 中 add_subdirectory 本模块 C++ 并 target_link_libraries。
  4. 在 PackageProvider.cpp 注册 RNAppAuthPackage(C++)。
  5. 在 RNPackagesFactory.ets 注册 RNAppAuthPackage(ETS)。

授权/登出重定向:在 entry module.json5 的 EntryAbility.skills.uris 中声明自定义 scheme(如 rnaa://oauth2redirect)。

本地验证可参考仓库 example:安装依赖、npm run dev 生成 bundle 后,用 DevEco Studio 打开 example/harmony 编译运行。

使用说明

import { authorize, prefetchConfiguration, refresh } from 'react-native-app-auth';

async function runAuthFlow() {
  const config = {
    issuer: 'https://demo.duendesoftware.com',
    clientId: 'interactive.public',
    redirectUrl: 'rnaa://oauth2redirect',
    scopes: ['openid', 'profile', 'email', 'offline_access'],
  };

  await prefetchConfiguration({ ...config, connectionTimeoutSeconds: 10 });

  const result = await authorize({ ...config, connectionTimeoutSeconds: 10 });
  console.log(result.accessToken, result.idToken);

  const refreshed = await refresh(config, { refreshToken: result.refreshToken });
  console.log(refreshed.accessToken);
}

接口文档

| API | 描述 | 参数 | 返回值 | HarmonyOS | |-----|------|------|--------|-----------| | prefetchConfiguration | 预取并缓存 OIDC 服务发现配置 | AuthConfiguration | Promise<void> | 返回 void(与 Android resolve boolean 不同) | | authorize | 授权码登录(PKCE、clientAuthMethod、附加参数) | AuthConfiguration | Promise<AuthorizeResult> | 系统浏览器 + 重定向回调 | | refresh | 使用刷新令牌获取新访问令牌 | AuthConfiguration, RefreshConfiguration | Promise<RefreshResult> | 支持 | | register | OIDC 动态客户端注册(DCR) | RegistrationConfiguration | Promise<RegistrationResponse> | 支持 | | revoke | 吊销访问令牌(JS fetch) | BaseAuthConfiguration, RevokeConfiguration | Promise<void> | 支持 | | logout | RP-Initiated Logout | EndSessionConfiguration, LogoutConfiguration | Promise<EndSessionResult> | 系统浏览器 + 重定向回调 |

平台差异要点:

  • warmAndPrefetchChrome 在鸿蒙为 no-op。
  • dangerouslyAllowInsecureHttpRequests 被忽略。
  • handleRedirect / cancelPendingFlow 为内部方法,不对业务开放。

快速验证(运行 Example)

前置条件

| 依赖 | 版本要求 | |------|----------| | Node.js | >= 18 | | DevEco Studio | 5.0+ | | HarmonyOS SDK | API 12+ |

运行步骤

1. 克隆仓库

git clone https://gitcode.com/hxa-rn/react-native-app-auth.git
cd react-native-app-auth
git checkout br_rnoh0.72

2. 安装仓库开发依赖

npm install --legacy-peer-deps

Example 已改为从 npm 公仓安装 @hxa-rn/[email protected],不再使用本地 file:../xxx.tgz,运行 Example 不必再执行 npm pack。

3. 进入 example 目录,安装依赖

cd example          # 或 example_auto
npm install --legacy-peer-deps

4. 生成 JS Bundle

npm run dev

产物:harmony/entry/src/main/resources/rawfile/bundle.harmony.js

5. 用 DevEco Studio 打开鸿蒙工程

  • 打开 DevEco Studio
  • 选择 example/harmony(或 example_auto/harmony)目录
  • 等待 Sync 完成

6. 编译并运行 HAP

在 DevEco Studio 中点击运行按钮,将 HAP 安装到设备/模拟器。

注意:Example 中已预置插件依赖和 Package 注册,无需手动配置 Link。Example 已声明 ohos.permission.INTERNET,并需在 entry module.json5 中配置 OAuth 重定向 scheme。

约束与限制

兼容性

  • 鸿蒙 SDK:API 12+
  • DevEco Studio:5.0+
  • 上游 RN 库:react-native-app-auth 8.1.0
  • React Native / RNOH:0.72+

权限

  • ohos.permission.INTERNET(entry module.json5 的 requestPermissions)

其它

  • authorize / logout 须声明自定义 redirect scheme,否则浏览器无法回跳。
  • 重定向回调依赖应用存活;进程被回收后挂起请求会丢失。
  • revoke 未配置 revocationEndpoint 时会请求 issuer 的 OIDC discovery(需网络)。

开源license

本项目基于 MIT 协议,详见 LICENSE 文件。

问题反馈渠道

使用问题请在 AtomGit 提交 Issue。也可在 GitCode 仓库反馈:

https://gitcode.com/hxa-rn/react-native-app-auth

https://gitcode.com/hxa-rn/react-native-app-auth/issues