Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (dispatch) => {
const uri = `${Config.OAUTH_SITE}api/public/${useDeckEndpoint ? 'deck' : 'decklist'}/${id}`;
fetch(uri, { method: 'GET' })
.then(response => {
if (response.ok === true) {
return response.json();
}
throw new Error(`Unexpected status: ${response.status}`);
})
.then(json => {
dispatch(updateDeck(id, json, false));
}).catch((err: Error) => {
if (!useDeckEndpoint) {
return dispatch(fetchPublicDeck(id, true));
}
console.log(err);
});
};
import { Platform } from 'react-native';
import Config from 'react-native-config';
import * as Keychain from 'react-native-keychain';
import { authorize, refresh, revoke, prefetchConfiguration, AuthorizeResult, RefreshResult } from 'react-native-app-auth';
const config: any = {
issuer: Config.OAUTH_SITE,
clientId: Config.OAUTH_CLIENT_ID,
clientSecret: Config.OAUTH_CLIENT_SECRET,
redirectUrl: 'arkhamcards://auth/redirect',
serviceConfiguration: {
authorizationEndpoint: `${Config.OAUTH_SITE}oauth/v2/auth`,
tokenEndpoint: `${Config.OAUTH_SITE}oauth/v2/token`,
revocationEndpoint: `${Config.OAUTH_SITE}oauth/v2/revoke`,
},
};
function saveAuthResponse(response: AuthorizeResult | RefreshResult) {
const serialized = JSON.stringify(response);
return Keychain.setGenericPassword('arkhamdb', serialized)
.then(() => {
return response.accessToken;
});
return getAccessToken().then(accessToken => {
if (!accessToken) {
throw new Error('badAccessToken');
}
const uri = `${Config.OAUTH_SITE}api/oauth2/deck/load/${id}?access_token=${accessToken}`;
return fetch(uri, {
method: 'GET',
}).then(response => {
if (response.status === 500) {
throw new Error('Not Found');
}
if (response.status !== 200) {
throw new Error('Invalid Deck Status');
}
return response.json().then(deck => {
if (deck && deck.id && deck.name && deck.slots) {
return cleanDeck(deck);
}
throw new Error('Invalid Deck Response');
});
});
import { Platform } from 'react-native';
import Config from 'react-native-config';
import * as Keychain from 'react-native-keychain';
import { authorize, refresh, revoke, prefetchConfiguration, AuthorizeResult, RefreshResult } from 'react-native-app-auth';
const config: any = {
issuer: Config.OAUTH_SITE,
clientId: Config.OAUTH_CLIENT_ID,
clientSecret: Config.OAUTH_CLIENT_SECRET,
redirectUrl: 'arkhamcards://auth/redirect',
serviceConfiguration: {
authorizationEndpoint: `${Config.OAUTH_SITE}oauth/v2/auth`,
tokenEndpoint: `${Config.OAUTH_SITE}oauth/v2/token`,
revocationEndpoint: `${Config.OAUTH_SITE}oauth/v2/revoke`,
},
};
function saveAuthResponse(response: AuthorizeResult | RefreshResult) {
const serialized = JSON.stringify(response);
return Keychain.setGenericPassword('arkhamdb', serialized)
.then(() => {
return response.accessToken;
});
}
export function getRefreshToken() {
return Keychain.getGenericPassword()
.then(creds => {