How to use react-native-app-auth - 10 common examples

To help you get started, we’ve selected a few react-native-app-auth examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oktadeveloper / okta-react-native-spring-boot-example / react-native-app / App / modules / login / login.sagas.js View on Github external
const authInfo = yield call(api.getOauthInfo)
  if (authInfo.ok) {
    const { issuer, scope } = authInfo.data
    const config = {
      issuer,
      clientId: '0oai6n2lojEIfg5pp0h7',
      scopes: scope.split(' '),
      redirectUrl: `${AppConfig.appUrlScheme}://authorize`
    }
    if (__DEV__ && Platform.OS === 'android') {
      // this allows connections to a keycloak instance using http:// in dev
      config.dangerouslyAllowInsecureHttpRequests = true
    }
    try {
      // result includes accessToken, accessTokenExpirationDate and refreshToken
      const authorizeResult = yield authorize(config)
      const { accessToken } = authorizeResult
      yield call(api.setAuthToken, accessToken)
      yield put(LoginActions.loginSuccess(accessToken))
      yield put(AccountActions.accountRequest())
      yield put({ type: 'RELOGIN_OK' })
    } catch (error) {
      console.log(error)
      yield put(LoginActions.loginFailure('WRONG'))
    }
  } else {
    yield put(LoginActions.loginFailure('WRONG'))
  }
}
github oktadeveloper / okta-react-native-spring-boot-example / react-native-app / app / modules / login / login.sagas.js View on Github external
const authInfo = yield call(api.getOauthInfo)
  if (authInfo.ok) {
    const { issuer, scope } = authInfo.data
    const config = {
      issuer,
      clientId: '{yourClientId}',
      scopes: scope.split(' '),
      redirectUrl: `${AppConfig.appUrlScheme}://authorize`
    }
    if (__DEV__ && Platform.OS === 'android') {
      // this allows connections to a keycloak instance using http:// in dev
      config.dangerouslyAllowInsecureHttpRequests = true
    }
    try {
      // result includes accessToken, accessTokenExpirationDate and refreshToken
      const authorizeResult = yield authorize(config)
      const { accessToken } = authorizeResult
      yield call(api.setAuthToken, accessToken)
      yield put(LoginActions.loginSuccess(accessToken))
      yield put(AccountActions.accountRequest())
      yield put({ type: 'RELOGIN_OK' })
    } catch (error) {
      console.log(error)
      yield put(LoginActions.loginFailure('WRONG'))
    }
  } else {
    yield put(LoginActions.loginFailure('WRONG'))
  }
}
github zzorba / ArkhamCards / lib / auth.ts View on Github external
.then(creds => {
      if (creds) {
        const data = JSON.parse(creds.password);
        const nowSeconds = (new Date()).getTime() / 1000;
        const expiration = new Date(data.accessTokenExpirationDate).getTime() / 1000;
        if (data.refreshToken && expiration < nowSeconds) {
          return refresh(config, { refreshToken: data.refreshToken })
            .then(
              saveAuthResponse,
              () => {
                // Null token will produce an error where it is used.
                return null;
              });
        }
        return data.accessToken;
      }
      return null;
    });
}
github mozilla / notes / native / app / vendor / fxa-utils.js View on Github external
.then((resp) => {
      // if 200 then token is valid, no need to review
      if (resp.status !== 200) {
        // if error attempt to renew access token
        return refresh(refreshConfig, {
          refreshToken: refreshToken
        });
      }
    }, () => {
      throw new Error('Failed to verify token');
github FormidableLabs / react-native-app-auth / Example / Latest / components / Advanced.js View on Github external
onlyAuthorize = async () => {
    try {
      const authResult = await onlyAuthorize(config);

      this.animateState(
        {
          authResult,
          tokenResult: null
        },
        500
      );

      this.setState({
        authResult,
        tokenResult: null
      });
    } catch (error) {
      Alert.alert('Failed to authorize', error.message);
    }
github forest-watcher / forest-watcher / app / redux-modules / user.js View on Github external
return async (dispatch: Dispatch) => {
    try {
      dispatch({ type: SET_LOGIN_LOADING, payload: true });
      const user = await authorize(oAuth.google);
      try {
        const response = await fetch(`${Config.API_AUTH}/auth/google/token?access_token=${user.accessToken}`);
        dispatch({ type: SET_LOGIN_LOADING, payload: false });
        if (!response.ok) throw new Error(response.status);
        const data = await response.json();
        dispatch({
          type: SET_LOGIN_AUTH,
          payload: {
            socialNetwork: 'google',
            loggedIn: true,
            token: data.token,
            oAuthToken: user.accessToken
          }
        });
      } catch (e) {
        console.error(e);
github forest-watcher / forest-watcher / app / redux-modules / user.js View on Github external
return async (dispatch: Dispatch, state: GetState) => {
    const { oAuthToken: tokenToRevoke, socialNetwork } = state().user;
    dispatch({ type: LOGOUT_REQUEST });
    dispatch({ type: RESET_STATE });

    try {
      await CookieManager.clearAll();

      const social = socialNetwork || socialNetworkFallback;
      switch (social) {
        case 'google': {
          if (tokenToRevoke) {
            await revoke(oAuth.google, { tokenToRevoke });
          }
          break;
        }
        case 'facebook':
          await LoginManager.logOut();
          break;
        default:
          break;
      }
      return dispatch({ type: SET_LOGIN_STATUS, payload: true });
    } catch (e) {
      console.error(e);
      return dispatch({ type: SET_LOGIN_STATUS, payload: false });
    }
  };
}
github FormidableLabs / react-native-app-auth / Example / AndroidExample / App.js View on Github external
authorize = async () => {
    try {
      const authState = await authorize(config);

      this.animateState(
        {
          hasLoggedInOnce: true,
          accessToken: authState.accessToken,
          accessTokenExpirationDate: authState.accessTokenExpirationDate,
          refreshToken: authState.refreshToken,
          scopes: authState.scopes,
        },
        500
      );
    } catch (error) {
      Alert.alert('Failed to log in', error.message);
    }
  };
github zzorba / ArkhamCards / lib / auth.ts View on Github external
export function signInFlow(): Promise {
  return authorize(config)
    .then(saveAuthResponse)
    .then(() => {
      return {
        success: true,
      };
    }, (error: Error) => {
      return {
        success: false,
        error: error.message || error,
      };
    });
}

react-native-app-auth

React Native bridge for AppAuth for supporting any OAuth 2 provider

MIT
Latest version published 3 months ago

Package Health Score

89 / 100
Full package analysis