@taretmch/capacitor-auth0
TypeScript icon, indicating that this package has built-in type declarations

5.0.0-beta.5 • Public • Published

@taretmch/capacitor-auth0

Native Auth0 SDK wrappter for capacitor

Install

npm install @taretmch/capacitor-auth0
npx cap sync

For iOS

Setup Auth0 domain & clientId at ios/App/App/Auth0.plist.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>ClientId</key>
    <string>{AUTH0_CLIENT_ID}</string>
    <key>Domain</key>
    <string>{AUTH0_DOMAIN}</string>
</dict>
</plist>

Setup Custom URL Scheme at Info.plist.

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
        </array>
    </dict>
</array>

capacitor-auth0 uses Auth0.swift internally. For more information, see Auth0.swift quickstart guide.

For Android

Setup Auth0 domain & clientId at android/app/src/main/res/values/strings.xml.

<?xml version='1.0' encoding='utf-8'?>
<resources>
    <string name="com_auth0_domain">{AUTH0_DOMAIN}</string>
    <string name="com_auth0_client_id">{AUTH0_CLIENT_ID}</string>
</resources>

Add manifestPlaceholders at android/app/build.gradle.

android {
    ...
    defaultConfig {
        ...
        manifestPlaceholders = [auth0Domain: "@string/com_auth0_domain", auth0Scheme: "demo"]
    }
}

capacitor-auth0 uses Auth0.Android internally. For more information, see Auth0.Android quickstart guide.

For Web

capacitor-auth0 has no implementation for web. You can use auth0-spa-js instead.

API

Capacitor Auth0 Plugin

load()

load() => Promise<Auth0User>

Load auth0 plugin. Get the authenticated user profile and update the credentials using the refresh token if the access token is expired. For android, initialize the plugin with your Auth0 configuration. Return undefined if the user is not authenticated.

Returns: Promise<Auth0User>


login()

login() => Promise<Auth0User>

Web Auth: Login with Auth0.

Returns: Promise<Auth0User>


logout()

logout() => Promise<void>

Web Auth: Logout from Auth0.


isAuthenticated()

isAuthenticated() => Promise<{ result: boolean; }>

Check if the user is authenticated.

Returns: Promise<{ result: boolean; }>


getUserInfo()

getUserInfo() => Promise<Auth0User>

Get the authenticated user profile. If the access token is expired, yield new credentials using the refresh token. Throws an error if the user is not authenticated.

Returns: Promise<Auth0User>


getCredentials()

getCredentials() => Promise<Credentials>

Get credentials and yield new credentials using the refresh token if the access token is expired. Return undefined if the user is not authenticated.

Returns: Promise<Credentials>


Interfaces

Auth0User

Auth0 user profile.

Prop Type Description
id string User ID.
name string User name.
email string User email.

Credentials

Auth0 credentials.

Prop Type Description
idToken string Identity token that contains user profile information.
accessToken string Access token for Auth0 API.
expiresAt string Access token expiration date. Once expired, the access token can no longer be used to access an API and a new access token needs to be obtained.
scope string Granted scopes for the access token. Undefined if no scope is granted.
refreshToken string Refresh token that can be used to request a new access token without signin again. Undefined if no refresh token is granted.
tokenType string Type of received token.

Readme

Keywords

Package Sidebar

Install

npm i @taretmch/capacitor-auth0

Weekly Downloads

5

Version

5.0.0-beta.5

License

MIT

Unpacked Size

45.4 kB

Total Files

27

Last publish

Collaborators

  • taretmch