5.1.0 • Published 11 months ago

@ist-group/react-native-oidc v5.1.0

Weekly downloads
3
License
ISC
Repository
-
Last release
11 months ago

REACT-NATIVE-OIDC

A library for OIDC communication and session management in react native.

NOTE that this library does not validate the tokens. Though it uses a nonce to protect against CSRF attacks and implements PKCE to protect against authorization code interception attack.

Usage

Initialization

import { SessionManager } from "react-native-oidc";

let sessionManager = new SessionManager({
    clientId: "APP_ID",
    clientSecret: "SECRET",
    authority: 'https://my-authority',
    redirectUri: "my-scheme:///",
    scope: "openid"
});

// Showing a splash screen/loading screen while checking if we have a valid session
showSplashScreen();

let hasActiveSession = await sessionManager.hasActiveSession();
if (hasActiveSession) {
    showUserHomeScreen();
} else {
    showLoginScreen();
}

Login

Login with username and password

Remarks:

  • Login with username and password requires resource owner grant.
try {
    await sessionManager.loginUsernamePassword(username, password);
    showUserHomeScreen();
} catch (e) {
    alert('Invalid username or password');
}

Login at authority via browser

try {
    await sessionManager.loginBrowser();
    showUserHomeScreen();
} catch (e) {
    alert('Something went wrong')
}

API calls

try {
    var accessToken = await sessionManager.getAccessToken();
    return await fetch(accessToken, data);
} catch (error) {
    if (error instanceof InvalidSesionError) {
        showLoginScreen('You have been logged out');
    }

    throw error;
}

Developing

Since the react-native packer doesn't work well with symbolic links the yarn link command cannot be used with this library. Instead use the node cpx cli to watch and copy files to the target project when developing:

  1. npm install cpx --global
  2. yarn start
  3. cpx "./dist/*/.*" ../my-app/node_modules/@ist-group/react-native-oidc/dist --watch --verbose
5.1.0

11 months ago

5.0.11

1 year ago

5.0.10

3 years ago

5.0.9

4 years ago

5.0.8

4 years ago

5.0.7

4 years ago

5.0.6

5 years ago

5.0.5

5 years ago

5.0.4

5 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.3.0

6 years ago

4.2.0

6 years ago

4.1.0

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago