@hxa-rn/rnaa 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +159 -0
- package/harmony/rnaa/LICENSE +21 -0
- package/harmony/rnaa/NOTICE +33 -0
- package/harmony/rnaa/OAT.xml +38 -0
- package/harmony/rnaa/build-profile.json5 +19 -0
- package/harmony/rnaa/hvigorfile.ts +2 -0
- package/harmony/rnaa/index.ets +1 -0
- package/harmony/rnaa/oh-package.json5 +14 -0
- package/harmony/rnaa/src/main/cpp/CMakeLists.txt +15 -0
- package/harmony/rnaa/src/main/cpp/RNAppAuthPackage.h +13 -0
- package/harmony/rnaa/src/main/cpp/generated/RNOH/generated/BaseRnaaPackage.h +72 -0
- package/harmony/rnaa/src/main/cpp/generated/RNOH/generated/turbo_modules/RNAppAuth.cpp +22 -0
- package/harmony/rnaa/src/main/cpp/generated/RNOH/generated/turbo_modules/RNAppAuth.h +16 -0
- package/harmony/rnaa/src/main/ets/DateUtil.ets +28 -0
- package/harmony/rnaa/src/main/ets/OAuthHttpClient.ets +293 -0
- package/harmony/rnaa/src/main/ets/OAuthProtocol.ets +293 -0
- package/harmony/rnaa/src/main/ets/PKCE.ets +105 -0
- package/harmony/rnaa/src/main/ets/RNAppAuthTurboModule.ets +713 -0
- package/harmony/rnaa/src/main/ets/RNAppAuthTurboModulesFactory.ets +18 -0
- package/harmony/rnaa/src/main/ets/Types.ets +98 -0
- package/harmony/rnaa/src/main/ets/generated/index.ets +5 -0
- package/harmony/rnaa/src/main/ets/generated/ts.ts +5 -0
- package/harmony/rnaa/src/main/ets/generated/turboModules/RNAppAuth.ts +38 -0
- package/harmony/rnaa/src/main/ets/generated/turboModules/ts.ts +5 -0
- package/harmony/rnaa/src/main/module.json5 +16 -0
- package/harmony/rnaa/src/main/resources/base/element/string.json +8 -0
- package/harmony/rnaa/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/rnaa/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/rnaa.har +0 -0
- package/package.json +69 -0
- package/src/index.d.ts +202 -0
- package/src/index.js +596 -0
- package/src/specs/v1/.gitkeep +1 -0
- package/src/specs/v1/NativeRNAppAuth.ts +138 -0
- package/src/specs/v2/.gitkeep +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hxa-rn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
本项目基于 [react-native-app-auth](https://github.com/FormidableLabs/react-native-app-auth)开发。如果在使用过程中有任何问题,欢迎在AtomGit提交Issue,会及时跟进。
|
|
2
|
+
|
|
3
|
+
## 项目介绍
|
|
4
|
+
|
|
5
|
+
`@hxa-rn/rnaa` 为 React Native 库 [react-native-app-auth](https://github.com/FormidableLabs/react-native-app-auth) 的鸿蒙适配包,提供 OAuth 2.0 / OpenID Connect 授权码流程(含 PKCE)、配置预取、令牌刷新、动态客户端注册、令牌吊销与会话登出。当前版本 `8.1.0`,对应上游 `8.1.0`,支持 Autolink,编译目标 API 12+。
|
|
6
|
+
|
|
7
|
+
## 集成指南
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @hxa-rn/rnaa
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**peerDependencies**:`react-native` >= 0.72。
|
|
14
|
+
|
|
15
|
+
包内已声明 `harmony.alias` 为 `react-native-app-auth`。业务代码在配置 alias 后仍从原库名导入:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { authorize, prefetchConfiguration, refresh } from 'react-native-app-auth';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
不要写成 `from '@hxa-rn/rnaa'`。
|
|
22
|
+
|
|
23
|
+
当前版本支持 Autolink;工程已接入时可跳过手动配置。如需 Manual Link:
|
|
24
|
+
|
|
25
|
+
1. 在工程根 `oh-package.json5` 配置 `@rnoh/react-native-openharmony` 的 overrides(按宿主工程约定)。
|
|
26
|
+
2. 在 `entry/oh-package.json5` 添加依赖:`"@hxa-rn/rnaa": "file:../../node_modules/@hxa-rn/rnaa/harmony/rnaa.har"`,并执行 `ohpm install`。
|
|
27
|
+
3. 在 `entry/src/main/cpp/CMakeLists.txt` 中 `add_subdirectory` 本模块 C++ 并 `target_link_libraries`。
|
|
28
|
+
4. 在 `PackageProvider.cpp` 注册 `RNAppAuthPackage`(C++)。
|
|
29
|
+
5. 在 `RNPackagesFactory.ets` 注册 `RNAppAuthPackage`(ETS)。
|
|
30
|
+
|
|
31
|
+
授权/登出重定向:在 entry `module.json5` 的 `EntryAbility.skills.uris` 中声明自定义 scheme(如 `rnaa://oauth2redirect`)。
|
|
32
|
+
|
|
33
|
+
本地验证可参考仓库 `example`:安装依赖、`npm run dev` 生成 bundle 后,用 DevEco Studio 打开 `example/harmony` 编译运行。
|
|
34
|
+
|
|
35
|
+
## 使用说明
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
import { authorize, prefetchConfiguration, refresh } from 'react-native-app-auth';
|
|
39
|
+
|
|
40
|
+
async function runAuthFlow() {
|
|
41
|
+
const config = {
|
|
42
|
+
issuer: 'https://demo.duendesoftware.com',
|
|
43
|
+
clientId: 'interactive.public',
|
|
44
|
+
redirectUrl: 'rnaa://oauth2redirect',
|
|
45
|
+
scopes: ['openid', 'profile', 'email', 'offline_access'],
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
await prefetchConfiguration({ ...config, connectionTimeoutSeconds: 10 });
|
|
49
|
+
|
|
50
|
+
const result = await authorize({ ...config, connectionTimeoutSeconds: 10 });
|
|
51
|
+
console.log(result.accessToken, result.idToken);
|
|
52
|
+
|
|
53
|
+
const refreshed = await refresh(config, { refreshToken: result.refreshToken });
|
|
54
|
+
console.log(refreshed.accessToken);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## 接口文档
|
|
59
|
+
|
|
60
|
+
| API | 描述 | 参数 | 返回值 | HarmonyOS |
|
|
61
|
+
|-----|------|------|--------|-----------|
|
|
62
|
+
| `prefetchConfiguration` | 预取并缓存 OIDC 服务发现配置 | `AuthConfiguration` | `Promise<void>` | 返回 void(与 Android resolve boolean 不同) |
|
|
63
|
+
| `authorize` | 授权码登录(PKCE、clientAuthMethod、附加参数) | `AuthConfiguration` | `Promise<AuthorizeResult>` | 系统浏览器 + 重定向回调 |
|
|
64
|
+
| `refresh` | 使用刷新令牌获取新访问令牌 | `AuthConfiguration`, `RefreshConfiguration` | `Promise<RefreshResult>` | 支持 |
|
|
65
|
+
| `register` | OIDC 动态客户端注册(DCR) | `RegistrationConfiguration` | `Promise<RegistrationResponse>` | 支持 |
|
|
66
|
+
| `revoke` | 吊销访问令牌(JS fetch) | `BaseAuthConfiguration`, `RevokeConfiguration` | `Promise<void>` | 支持 |
|
|
67
|
+
| `logout` | RP-Initiated Logout | `EndSessionConfiguration`, `LogoutConfiguration` | `Promise<EndSessionResult>` | 系统浏览器 + 重定向回调 |
|
|
68
|
+
|
|
69
|
+
平台差异要点:
|
|
70
|
+
|
|
71
|
+
- `warmAndPrefetchChrome` 在鸿蒙为 no-op。
|
|
72
|
+
- `dangerouslyAllowInsecureHttpRequests` 被忽略。
|
|
73
|
+
- `handleRedirect` / `cancelPendingFlow` 为内部方法,不对业务开放。
|
|
74
|
+
|
|
75
|
+
## 快速验证(运行 Example)
|
|
76
|
+
|
|
77
|
+
### 前置条件
|
|
78
|
+
|
|
79
|
+
| 依赖 | 版本要求 |
|
|
80
|
+
|------|----------|
|
|
81
|
+
| Node.js | >= 18 |
|
|
82
|
+
| DevEco Studio | 5.0+ |
|
|
83
|
+
| HarmonyOS SDK | API 12+ |
|
|
84
|
+
|
|
85
|
+
### 运行步骤
|
|
86
|
+
|
|
87
|
+
**1. 克隆仓库**
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
git clone https://gitcode.com/hxa-rn/react-native-app-auth.git
|
|
91
|
+
cd react-native-app-auth
|
|
92
|
+
git checkout br_rnoh0.72
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**2. 安装仓库开发依赖**
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
npm install --legacy-peer-deps
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Example 已改为从 npm 公仓安装 `@hxa-rn/rnaa@8.1.0`,不再使用本地 `file:../xxx.tgz`,运行 Example 不必再执行 `npm pack`。
|
|
102
|
+
|
|
103
|
+
**3. 进入 example 目录,安装依赖**
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
cd example # 或 example_auto
|
|
107
|
+
npm install --legacy-peer-deps
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**4. 生成 JS Bundle**
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npm run dev
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
产物:`harmony/entry/src/main/resources/rawfile/bundle.harmony.js`
|
|
117
|
+
|
|
118
|
+
**5. 用 DevEco Studio 打开鸿蒙工程**
|
|
119
|
+
|
|
120
|
+
- 打开 DevEco Studio
|
|
121
|
+
- 选择 `example/harmony`(或 `example_auto/harmony`)目录
|
|
122
|
+
- 等待 Sync 完成
|
|
123
|
+
|
|
124
|
+
**6. 编译并运行 HAP**
|
|
125
|
+
|
|
126
|
+
在 DevEco Studio 中点击运行按钮,将 HAP 安装到设备/模拟器。
|
|
127
|
+
|
|
128
|
+
> **注意**:Example 中已预置插件依赖和 Package 注册,无需手动配置 Link。Example 已声明 `ohos.permission.INTERNET`,并需在 entry `module.json5` 中配置 OAuth 重定向 scheme。
|
|
129
|
+
|
|
130
|
+
## 约束与限制
|
|
131
|
+
|
|
132
|
+
**兼容性**
|
|
133
|
+
|
|
134
|
+
- 鸿蒙 SDK:API 12+
|
|
135
|
+
- DevEco Studio:5.0+
|
|
136
|
+
- 上游 RN 库:react-native-app-auth `8.1.0`
|
|
137
|
+
- React Native / RNOH:0.72+
|
|
138
|
+
|
|
139
|
+
**权限**
|
|
140
|
+
|
|
141
|
+
- `ohos.permission.INTERNET`(entry `module.json5` 的 `requestPermissions`)
|
|
142
|
+
|
|
143
|
+
**其它**
|
|
144
|
+
|
|
145
|
+
- `authorize` / `logout` 须声明自定义 redirect scheme,否则浏览器无法回跳。
|
|
146
|
+
- 重定向回调依赖应用存活;进程被回收后挂起请求会丢失。
|
|
147
|
+
- `revoke` 未配置 `revocationEndpoint` 时会请求 issuer 的 OIDC discovery(需网络)。
|
|
148
|
+
|
|
149
|
+
## 开源license
|
|
150
|
+
|
|
151
|
+
本项目基于 MIT 协议,详见 [LICENSE](LICENSE) 文件。
|
|
152
|
+
|
|
153
|
+
## 问题反馈渠道
|
|
154
|
+
|
|
155
|
+
使用问题请在 AtomGit 提交 Issue。也可在 GitCode 仓库反馈:
|
|
156
|
+
|
|
157
|
+
https://gitcode.com/hxa-rn/react-native-app-auth
|
|
158
|
+
|
|
159
|
+
https://gitcode.com/hxa-rn/react-native-app-auth/issues
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hxa-rn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
OPEN SOURCE SOFTWARE NOTICE
|
|
2
|
+
|
|
3
|
+
Please note we provide an open source software notice for the third party open source software along with this software and/or this software component (in the following just “this SOFTWARE”). The open source software licenses are granted by the respective right holders.
|
|
4
|
+
|
|
5
|
+
Warranty Disclaimer
|
|
6
|
+
THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
|
|
7
|
+
|
|
8
|
+
Copyright Notice and License Texts
|
|
9
|
+
|
|
10
|
+
----------------------------------------------------------------------
|
|
11
|
+
Software: react-native-netinfo V11.1.0
|
|
12
|
+
|
|
13
|
+
MIT License
|
|
14
|
+
|
|
15
|
+
Copyright (c) 2015-present, Facebook, Inc.
|
|
16
|
+
|
|
17
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
18
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
19
|
+
in the Software without restriction, including without limitation the rights
|
|
20
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
21
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
22
|
+
furnished to do so, subject to the following conditions:
|
|
23
|
+
|
|
24
|
+
The above copyright notice and this permission notice shall be included in all
|
|
25
|
+
copies or substantial portions of the Software.
|
|
26
|
+
|
|
27
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
28
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
29
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
30
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
31
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
32
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
|
+
SOFTWARE.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<configuration>
|
|
3
|
+
<oatconfig>
|
|
4
|
+
<licensefile>LICENSE</licensefile>
|
|
5
|
+
<filefilterlist>
|
|
6
|
+
<filefilter name="copyrightPolicyFilter" desc="Filters for compatibility,license header policies">
|
|
7
|
+
<filteritem type="filename" name="hvigorfile.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不需要添加版权头"/>
|
|
8
|
+
<filteritem type="filename" name="*.json5" desc="hvigor工程配置文件,DevEco Studio自动生成,不需要添加版权头"/>
|
|
9
|
+
<filteritem type="filename" name="*.proto" desc="资源文件,不需要添加版权头"/>
|
|
10
|
+
<filteritem type="filename" name="*.json" desc="资源文件,不需要添加版权头"/>
|
|
11
|
+
<filteritem type="filepath" name="hvigorw" desc="工程模板,不修改版权头,以防有修改版权风险"/>
|
|
12
|
+
<filteritem type="filepath" name="hvigorw.bat" desc="工程模板,不修改版权头,以防有修改版权风险"/>
|
|
13
|
+
<filteritem type="filepath" name="hvigor/hvigor-wrapper.js" desc="工程模板,不修改版权头,以防有修改版权风险"/>
|
|
14
|
+
<filteritem type="filename" name="LICENSE" desc="工程文件,不修改版权头"/>
|
|
15
|
+
</filefilter>
|
|
16
|
+
<filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
|
|
17
|
+
<filteritem type="filename" name="hvigorfile.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不需要添加许可证头"/>
|
|
18
|
+
<filteritem type="filename" name="*.json5" desc="hvigor工程配置文件,DevEco Studio自动生成,不需要添加许可证头"/>
|
|
19
|
+
<filteritem type="filename" name="LICENSE" desc="原三方库证书文件无需更改,因此添加过滤"/>
|
|
20
|
+
<filteritem type="filename" name="*.proto" desc="资源文件,不需要添加许可证头"/>
|
|
21
|
+
<filteritem type="filename" name="*.json" desc="资源文件,不需要添加许可证头"/>
|
|
22
|
+
<filteritem type="filepath" name="hvigorw" desc="工程模板,不修改版权头,以防有修改版权风险"/>
|
|
23
|
+
<filteritem type="filepath" name="hvigorw.bat" desc="工程模板,不修改版权头,以防有修改版权风险"/>
|
|
24
|
+
<filteritem type="filepath" name="hvigor/hvigor-wrapper.js" desc="工程模板,不修改版权头,以防有修改版权风险"/>
|
|
25
|
+
</filefilter>
|
|
26
|
+
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for resources files policies">
|
|
27
|
+
<filteritem type="filename" name="icon.png" desc="应用图标"/>
|
|
28
|
+
<filteritem type="filename" name="app_icon.png" desc="应用图标"/>
|
|
29
|
+
<filteritem type="filename" name="warn.png" desc="页面展示图标"/>
|
|
30
|
+
</filefilter>
|
|
31
|
+
</filefilterlist>
|
|
32
|
+
<policylist>
|
|
33
|
+
<policy name="projectPolicy" desc="">
|
|
34
|
+
<policyitem type="license" name="MIT" path="*.*" desc="license under the MIT"/>
|
|
35
|
+
</policy>
|
|
36
|
+
</policylist>
|
|
37
|
+
</oatconfig>
|
|
38
|
+
</configuration>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"apiType": "stageMode",
|
|
3
|
+
"buildOption": {
|
|
4
|
+
"arkOptions": {
|
|
5
|
+
"byteCodeHar": false
|
|
6
|
+
},
|
|
7
|
+
"packingOptions": {
|
|
8
|
+
"asset": {
|
|
9
|
+
"include": ["./src/main/cpp/**"]
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"targets": [
|
|
14
|
+
{
|
|
15
|
+
"name": "default",
|
|
16
|
+
"runtimeOS": "HarmonyOS"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { RNAppAuthPackage as default } from './src/main/ets/RNAppAuthTurboModulesFactory';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"license": "Apache-2.0",
|
|
3
|
+
"devDependencies": {
|
|
4
|
+
|
|
5
|
+
},
|
|
6
|
+
"author": "",
|
|
7
|
+
"name": "@hxa-rn/rnaa",
|
|
8
|
+
"description": "React Native bridge for AppAuth for supporting any OAuth 2 provider",
|
|
9
|
+
"main": "index.ets",
|
|
10
|
+
"version": "8.1.0",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@rnoh/react-native-openharmony": "file:../react_native_openharmony_release.har"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# the minimum version of CMake.
|
|
2
|
+
cmake_minimum_required(VERSION 3.13)
|
|
3
|
+
set(CMAKE_VERBOSE_MAKEFILE on)
|
|
4
|
+
|
|
5
|
+
# react-native codegen-harmony 将 C++ 产物放在 generated/;#include 以 src/main/cpp 为根(如 generated/Foo.h),
|
|
6
|
+
# 同时 generated 下的 .cpp 常使用 #include "Foo.h",故需同时加入 cpp 与 cpp/generated。
|
|
7
|
+
set(library_generated_dir "${CMAKE_CURRENT_SOURCE_DIR}/generated")
|
|
8
|
+
# 不用 **/*.cpp:OHOS 自带 CMake 在 Windows 上常匹配不到,会得到空列表 → add_library 报 No SOURCES。
|
|
9
|
+
file(GLOB_RECURSE library_generated_SRC CONFIGURE_DEPENDS "${library_generated_dir}/*.cpp")
|
|
10
|
+
file(GLOB library_SRC CONFIGURE_DEPENDS *.cpp)
|
|
11
|
+
add_library(rnaa SHARED ${library_SRC} ${library_generated_SRC})
|
|
12
|
+
target_include_directories(rnaa PUBLIC
|
|
13
|
+
${CMAKE_CURRENT_SOURCE_DIR}
|
|
14
|
+
${library_generated_dir})
|
|
15
|
+
target_link_libraries(rnaa PUBLIC rnoh)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#ifndef RNAPPAUTHPACKAGE_H
|
|
2
|
+
#define RNAPPAUTHPACKAGE_H
|
|
3
|
+
|
|
4
|
+
#include "generated/RNOH/generated/BaseRnaaPackage.h"
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
namespace rnoh {
|
|
8
|
+
class RNAppAuthPackage : public BaseRnaaPackage {
|
|
9
|
+
using Super = BaseRnaaPackage;
|
|
10
|
+
using Super::Super;
|
|
11
|
+
};
|
|
12
|
+
} // namespace rnoh
|
|
13
|
+
#endif //RNAPPAUTHPACKAGE_H
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "RNOH/Package.h"
|
|
8
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
9
|
+
#include "RNOH/generated/turbo_modules/RNAppAuth.h"
|
|
10
|
+
|
|
11
|
+
namespace rnoh {
|
|
12
|
+
|
|
13
|
+
class BaseRnaaPackageTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
14
|
+
public:
|
|
15
|
+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
|
|
16
|
+
if (name == "RNAppAuth") {
|
|
17
|
+
return std::make_shared<RNAppAuth>(ctx, name);
|
|
18
|
+
}
|
|
19
|
+
return nullptr;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
class BaseRnaaPackageEventEmitRequestHandler : public EventEmitRequestHandler {
|
|
24
|
+
public:
|
|
25
|
+
void handleEvent(Context const &ctx) override {
|
|
26
|
+
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
27
|
+
auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
|
|
28
|
+
|
|
29
|
+
if (eventEmitter == nullptr) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
std::vector<std::string> supportedComponentNames = {
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
std::vector<std::string> supportedEventNames = {
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
|
|
40
|
+
std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
41
|
+
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class BaseRnaaPackage : public Package {
|
|
48
|
+
public:
|
|
49
|
+
BaseRnaaPackage(Package::Context ctx) : Package(ctx){};
|
|
50
|
+
|
|
51
|
+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
|
|
52
|
+
return std::make_unique<BaseRnaaPackageTurboModuleFactoryDelegate>();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
|
|
56
|
+
return {
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
ComponentJSIBinderByString createComponentJSIBinderByName() override {
|
|
61
|
+
return {
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
EventEmitRequestHandlers createEventEmitRequestHandlers() override {
|
|
66
|
+
return {
|
|
67
|
+
std::make_shared<BaseRnaaPackageEventEmitRequestHandler>(),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#include "RNAppAuth.h"
|
|
6
|
+
|
|
7
|
+
namespace rnoh {
|
|
8
|
+
using namespace facebook;
|
|
9
|
+
|
|
10
|
+
RNAppAuth::RNAppAuth(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) {
|
|
11
|
+
methodMap_ = {
|
|
12
|
+
ARK_ASYNC_METHOD_METADATA(prefetchConfiguration, 9),
|
|
13
|
+
ARK_ASYNC_METHOD_METADATA(register, 11),
|
|
14
|
+
ARK_ASYNC_METHOD_METADATA(authorize, 14),
|
|
15
|
+
ARK_ASYNC_METHOD_METADATA(refresh, 12),
|
|
16
|
+
ARK_ASYNC_METHOD_METADATA(logout, 6),
|
|
17
|
+
ARK_ASYNC_METHOD_METADATA(handleRedirect, 1),
|
|
18
|
+
ARK_ASYNC_METHOD_METADATA(cancelPendingFlow, 0),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
8
|
+
|
|
9
|
+
namespace rnoh {
|
|
10
|
+
|
|
11
|
+
class JSI_EXPORT RNAppAuth : public ArkTSTurboModule {
|
|
12
|
+
public:
|
|
13
|
+
RNAppAuth(const ArkTSTurboModule::Context ctx, const std::string name);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timestamp formatting aligned with DateUtil.java on Android:
|
|
3
|
+
* 'yyyy-MM-dd\'T\'HH:mm:ss\'Z\'' (UTC, no milliseconds).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export class DateUtil {
|
|
7
|
+
/**
|
|
8
|
+
* Format a Unix timestamp (milliseconds since epoch) as an RFC 3339-ish
|
|
9
|
+
* UTC string without fractional seconds: 2024-01-01T00:00:00Z.
|
|
10
|
+
*/
|
|
11
|
+
static formatTimestamp(timestamp: number): string {
|
|
12
|
+
let date = new Date(timestamp);
|
|
13
|
+
let year = date.getUTCFullYear();
|
|
14
|
+
let month = DateUtil.pad2(date.getUTCMonth() + 1);
|
|
15
|
+
let day = DateUtil.pad2(date.getUTCDate());
|
|
16
|
+
let hours = DateUtil.pad2(date.getUTCHours());
|
|
17
|
+
let minutes = DateUtil.pad2(date.getUTCMinutes());
|
|
18
|
+
let seconds = DateUtil.pad2(date.getUTCSeconds());
|
|
19
|
+
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}Z`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private static pad2(value: number): string {
|
|
23
|
+
if (value < 10) {
|
|
24
|
+
return `0${value}`;
|
|
25
|
+
}
|
|
26
|
+
return `${value}`;
|
|
27
|
+
}
|
|
28
|
+
}
|