-
Notifications
You must be signed in to change notification settings - Fork 462
Closed
Description
Get rid of the AppAuth class and make the api function-based
Currently API:
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);Proposed API:
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);Pros
- API is easier to grasp, as it gets rid of the extra step of creating a new instance of AppAuth
- Easier to extend: the config is just an object
Cons
- There is more repetition
- Easier to lose track of shared config
- Config validation has to be done in every exposed function rather than once when instantiating
no23reason
Metadata
Metadata
Assignees
Labels
No labels