@plantimer/nativescript-auth0
Auth0 插件包装器。它使用 InAppBrowser 和 SecureStorage 来安全地验证用户。
npm i --save @plantimer/nativescript-auth0

@plantimer/nativescript-auth0

npm install @plantimer/nativescript-auth0

它是如何工作的?

目前支持的唯一工作流程是带有刷新令牌的 授权码授予与 PKCE

如果您没有启用刷新令牌设置,则此功能将无法工作!

按照 Auth0 文档中给出的图示,流程如下

  • 用户将被重定向到带有 PKCE 挑战的 Auth0 登录页面
  • 用户登录后,将带访问码重定向回应用程序
  • 应用程序将使用访问码、PKCE 挑战和 PKCE 验证器获取的刷新令牌进行存储
  • 应用程序使用刷新令牌获取访问令牌

用法

此插件使用 InAppBrowser 插件打开 Auth0 登录页面,并使用 NativeScript Secure Storage 插件存储令牌。

import { Auth0 } from '@plantimer/nativescript-auth0';

const config = {
auth0Config: {
domain: 'mydomain.auth0.com', // Domain name given by Auth0 or your own domain if you have a paid plan
clientId: 'ClIenTiDgIvEnByAuTh0', // Client ID given by Auth0
audience: 'https://your.audience.com', // Often a URL
redirectUri: 'schema:///', // The app's schema (set in AndroidManifest.xml and Info.plist)
},
browserConfig: {
// InAppBrowser configuration
}
}

Auth0.setUp(config).signUp("[email protected]"); // Optional hint to pre-fill the email field
Auth0.setUp(config).signIn();
Auth0.setUp(config).getAccessToken();

Angular 示例

// *.component.ts
import { NativescriptAuth0 } from '@plantimer/nativescript-auth0';

@Component({
selector: 'ns-app',
template: '<Button (tap)="login()">Login</Button>',
})
export class AppComponent {
login() {
const config = {
auth0Config: {
domain: 'mydomain.auth0.com', // Domain name given by Auth0 or your own domain if you have a paid plan
clientId: 'ClIenTiDgIvEnByAuTh0', // Client ID given by Auth0
audience: 'https://your.audience.com', // Often a URL
redirectUri: 'schema:///', // The app's schema (set in AndroidManifest.xml and Info.plist)
},
browserConfig: {
// InAppBrowser configuration
}
}

Auth0.setUp(config).signUp("[email protected]"); // Optional hint to pre-fill the email field
Auth0.setUp(config).signIn();
Auth0.setUp(config).getAccessToken();
}
}

启用深度链接

深度链接是指当点击链接时打开应用程序的能力。这是使 redirectUri 工作所必需的。

请按照 InAppBrowser 文档 中的说明启用深度链接(即设置模式)。

想法和问题

如果您有任何想法、问题或安全担忧,请提出问题!

许可证

此存储库可在 MIT 许可证 下使用。