How to use the react-native-keychain.getInternetCredentials function in react-native-keychain

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

github oblador / react-native-keychain / test_index.js View on Github external
setInternetCredentials('server', 'username', 'password');
setInternetCredentials('server', 'username', 'password', simpleOptions).then(
  result => {
    (result: void);
  }
);

// $FlowExpectedError - First argument is required
hasInternetCredentials();
hasInternetCredentials('server').then(result => {
  (result: boolean);
});

// $FlowExpectedError - First argument is required
getInternetCredentials();
getInternetCredentials('server', simpleOptions).then(credentials => {
  if (credentials) {
    (credentials.username: string);
    (credentials.password: string);
  }
});

// $FlowExpectedError - First argument is required
resetInternetCredentials();
resetInternetCredentials('server', simpleOptions).then(result => {
  (result: void);
});

// $FlowExpectedError - First two arguments are required
setGenericPassword();
setGenericPassword('username', 'password').then(result => {
  (result: boolean);
github N3TC4T / artunis-mobile / src / libs / vault.js View on Github external
retrieve: async (type: string): KeychainData | boolean =>
        // eslint-disable-next-line no-return-await
        await Keychain.getInternetCredentials(type)
            .then((data: KeychainData): KeychainData | boolean => {
                if (!data) {
                    return false;
                }
                return data;
            })
            .catch((error: string): boolean => {
                console.error('Keychain could not be accessed! Maybe no value set?', error);
                return false;
            }),
github UCSD / campus-mobile / app / util / auth.js View on Github external
* authorizedPublicFetch(endpoint, payload) {
		yield put({ type: 'AUTH_HTTP_REQUEST' })

		// Check to see if we aren't in an error state
		const userState = state => (state.user)
		const { appUpdateRequired } = yield select(userState)
		if (appUpdateRequired) {
			const e = new Error('App update required.')
			yield put({ type: 'AUTH_HTTP_FAILURE', e })
			throw e
		}


		let accessToken = yield Keychain
			.getInternetCredentials(publicTokenSiteName)
			.then(credentials => (credentials.password))

		try {
			let endpointResponse
			if (payload) endpointResponse = yield authorizedPostRequest(endpoint, accessToken, payload)
			else endpointResponse = yield authorizedFetchRequest(endpoint, accessToken)

			// Refresh token if invalidToken and retry request
			if (endpointResponse.invalidToken) {
				for (
					let i = 0, remainingRetries = MOBILE_PUBLIC_TOKEN_MAX_RETRIES;
					remainingRetries > 0;
					remainingRetries--, i++
				) {
					// Attempt to get a new access token
github mattermost / mattermost-mobile / app / init / credentials.js View on Github external
async function getInternetCredentials(url) {
    try {
        const credentials = await KeyChain.getInternetCredentials(url);

        if (credentials) {
            const usernameParsed = credentials.username.split(',');
            const token = credentials.password;
            const [deviceToken, currentUserId] = usernameParsed;

            if (token && token !== 'undefined') {
                EphemeralStore.deviceToken = deviceToken;
                Client4.setUserId(currentUserId);
                Client4.setUrl(url);
                Client4.setToken(token);
                await setCSRFFromCookie(url);

                return credentials;
            }
        }
github StoDevX / AAO-React-Native / source / lib / login.js View on Github external
export function loadLoginCredentials(): Promise<{
	username?: string,
	password?: string,
}> {
	return Keychain.getInternetCredentials(SIS_LOGIN_CREDENTIAL_KEY).catch(
		() => ({}),
	)
}
export function clearLoginCredentials() {
github jarden-digital / react-native-pincode / src / utils.ts View on Github external
export const hasPinCode = async (serviceName: string) => {
  return await Keychain.getInternetCredentials(serviceName).then(res => {
    return !!res && !!res.password
  })
}
github jarden-digital / react-native-pincode / dist / src / PinCodeEnter.js View on Github external
async componentWillMount() {
        if (!this.props.storedPin) {
            const result = await Keychain.getInternetCredentials(this.props.pinCodeKeychainName);
            this.keyChainResult = result.password || undefined;
        }
    }
    componentDidMount() {
github iotaledger / trinity-wallet / src / mobile / src / libs / keychain.js View on Github external
get: (alias) => {
        return Keychain.getInternetCredentials(alias).then((credentials) => {
            if (isEmpty(credentials)) {
                return null;
            }

            const payload = {
                nonce: get(credentials, 'username'),
                item: get(credentials, 'password'),
            };

            return payload;
        });
    },
    /**
github infinitered / ignite-bowser / boilerplate / app / utils / keychain.ts View on Github external
export async function load(server?: string) {
  if (server) {
    const creds = await ReactNativeKeychain.getInternetCredentials(server)
    return {
      username: creds.username,
      password: creds.password,
      server,
    }
  } else {
    const creds = await ReactNativeKeychain.getGenericPassword()
    if (typeof creds === "object") {
      return {
        username: creds.username,
        password: creds.password,
        server: null,
      }
    } else {
      return {
        username: null,
github developmentseed / observe / app / services / auth.js View on Github external
export async function getOAuthHeaders (url, method = 'GET', body = null) {
  if (await isAuthorized()) {
    const {
      username: accessToken,
      password: accessTokenSecret
    } = await Keychain.getInternetCredentials(Config.API_URL)

    return oauth.toHeader(
      oauth.authorize(
        {
          url,
          method,
          body
        },
        {
          key: accessToken,
          secret: accessTokenSecret
        }
      )
    )
  }