Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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;
}),
* 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
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;
}
}
export function loadLoginCredentials(): Promise<{
username?: string,
password?: string,
}> {
return Keychain.getInternetCredentials(SIS_LOGIN_CREDENTIAL_KEY).catch(
() => ({}),
)
}
export function clearLoginCredentials() {
export const hasPinCode = async (serviceName: string) => {
return await Keychain.getInternetCredentials(serviceName).then(res => {
return !!res && !!res.password
})
}
async componentWillMount() {
if (!this.props.storedPin) {
const result = await Keychain.getInternetCredentials(this.props.pinCodeKeychainName);
this.keyChainResult = result.password || undefined;
}
}
componentDidMount() {
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;
});
},
/**
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,
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
}
)
)
}