How to use the react-native-app-auth.authorize function in react-native-app-auth

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 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 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,
      };
    });
}
github oktadeveloper / okta-react-native-app-auth-example / 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,
          idToken: authState.idToken
        },
        500
      );
    } catch (error) {
      Alert.alert('Failed to log in', error.message);
    }
  };
github FormidableLabs / react-native-app-auth / Example / iOSCarthageExample / 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);
    }
  };

react-native-app-auth

React Native bridge for AppAuth for supporting any OAuth 2 provider

MIT
Latest version published 9 days ago

Package Health Score

93 / 100
Full package analysis