import AppAuth from 'react-native-app-auth';
const refreshTokenConfig = {
issuer: <ISSUER>,
redirectUrl: <REDIRECT_URL>,
clientId: <CLIENT_ID>,
additionalParameters: <ADDITIONAL_PARAMETERS>
};
const appAuth = new AppAuth(config);
// authorize
const scopes = [SCOPES];
const result = await appAuth.authorize(scopes);
// refresh
const scopes = [SCOPES];
const result = await appAuth.refresh(scopes);
// revoke
const tokenToRevoke = <TOKEN>;
const sendClientId = BOOLEAN;
const result = await appAuth.revokeToken(tokenToRevoke, sendClientId = false);
import { authorize, refresh, revokeToken } from 'react-native-app-auth';
// authorize
const authorizeConfig = {
issuer: <ISSUER>,
redirectUrl: <REDIRECT_URL>,
clientId: <CLIENT_ID>,
scopes: [SCOPES],
additionalParameters: <ADDITIONAL_PARAMETERS>
};
const result = await authorize(authorizeConfig);
// refresh
const refreshTokenConfig = {
issuer: <ISSUER>,
redirectUrl: <REDIRECT_URL>,
clientId: <CLIENT_ID>,
refreshToken: <TOKEN>,
scopes: [SCOPES],
additionalParameters: <ADDITIONAL_PARAMETERS>
};
const result = await refresh(refreshTokenConfig);
// revoke
const revokeTokenConfig = {
issuer: <ISSUER>,
clientId: <CLIENT_ID>,
tokenToRevoke: <TOKEN>,
sendClientId: BOOLEAN
};
const result = await revokeToken(revokeTokenConfig);
How about allowing sharing the configuration for all three methods. This is basically exactly what you are doing, with the exception that the revoke method needs to be able to handle being passed fields it won't use (scopes, redirectUrl).
import { authorize, refresh, revoke } from 'react-native-app-auth';
// authorize
const baseConfig = {
issuer: <ISSUER>,
redirectUrl: <REDIRECT_URL>,
clientId: <CLIENT_ID>,
scopes: [SCOPES],
additionalParameters: <ADDITIONAL_PARAMETERS>
};
// authenticate
const result = await authorize(baseConfig);
// refresh
const result = await refresh({
...baseConfig,
refreshToken: result.refreshToken,
});
// revoke
const result = await revoke({
...baseConfig,
tokenToRevoke: result.accessToken,
sendClientId: BOOLEAN
});
When you make this change, can you add a note to README saying something like "This is the API documentation for react-native-app-auth >= 2.0. See version 1.x documentation here." with a link to latest 1.x tag.
Done and v2.0.0 published 馃帀
Most helpful comment
How about allowing sharing the configuration for all three methods. This is basically exactly what you are doing, with the exception that the
revokemethod needs to be able to handle being passed fields it won't use (scopes, redirectUrl).