Skip to content

Commit

Permalink
Revert "provided fix for an edge case"
Browse files Browse the repository at this point in the history
This reverts commit d8ac5bf.
  • Loading branch information
asadali214 committed Apr 9, 2024
1 parent d8ac5bf commit 263ab59
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
4 changes: 1 addition & 3 deletions packages/oauth-adapters/src/oauthAuthenticationAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { AUTHORIZATION_HEADER, setHeader } from '@apimatic/http-headers';

export const requestAuthenticationProvider = (
initialOAuthToken?: OAuthToken,
oAuthTokenProvider?: (
token: OAuthToken | undefined
) => Promise<OAuthToken | undefined>,
oAuthTokenProvider?: (token: OAuthToken | undefined) => Promise<OAuthToken>,
oAuthOnTokenUpdate?: (token: OAuthToken) => void
): AuthenticatorInterface<boolean> => {
// This token is shared between all API calls for a client instance.
Expand Down
29 changes: 22 additions & 7 deletions packages/oauth-adapters/test/oauthAuthenticationAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,18 @@ describe('test oauth request provider', () => {
};
const authenticationProvider = requestAuthenticationProvider(
oAuthToken,
(_: OAuthToken | undefined) => {
// return an undefined token if accessed from provider
return Promise.resolve(undefined);
(token: OAuthToken | undefined) => {
// return an invalid token if accessed from provider
if (token === undefined) {
return Promise.resolve({
accessToken: 'Invalid',
tokenType: 'Bearer',
});
}
return Promise.resolve({
...token,
accessToken: 'Invalid',
});
},
(_: OAuthToken) => {
// fail if token gets updated
Expand Down Expand Up @@ -82,8 +91,11 @@ describe('test oauth request provider', () => {
expiry: BigInt(Date.now()),
});
}
// return an undefined token if existing token is not undefined
return Promise.resolve(undefined);
// return an invalid token if existing token is not undefined
return Promise.resolve({
...token,
accessToken: 'Invalid',
});
},
(token: OAuthToken) => {
// check the updated token
Expand Down Expand Up @@ -124,8 +136,11 @@ describe('test oauth request provider', () => {
oAuthToken,
(token: OAuthToken | undefined) => {
if (token === undefined) {
// return if existing token is undefined
return Promise.resolve(token);
// return an invalid token if existing token is undefined
return Promise.resolve({
accessToken: 'Invalid',
tokenType: 'Bearer',
});
}
return Promise.resolve({
...token,
Expand Down

0 comments on commit 263ab59

Please sign in to comment.