Skip to content

Proposal: v2.0.0 #35

@kadikraman

Description

@kadikraman

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions