Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1196 from Shopify/deprecate-unstable-tokenExchang…
Browse files Browse the repository at this point in the history
…e-flag

Ensure tokenExchange is always available regardless of unstable_tokenExchange setting
  • Loading branch information
rezaansyed authored Feb 9, 2024
2 parents fb28aed + 976f193 commit 19eedf8
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-gorillas-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopify/shopify-api": patch
---

Remove gating of the token exchange API behind the unstable_tokenExchange flag.
4 changes: 1 addition & 3 deletions packages/shopify-api/adapters/__e2etests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export const config: ConfigInterface = {
httpRequests: false,
timestamps: false,
},
future: {
unstable_tokenExchange: true,
},
future: {},
};

export const session = new Session({
Expand Down
15 changes: 2 additions & 13 deletions packages/shopify-api/docs/guides/oauth.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,8 @@ See ["new embedded app authorization Strategy"](https://shopify.dev/docs/api/sho
- [configured through the Shopify CLI](https://shopify.dev/docs/apps/tools/cli/configuration) or
- install your app through the [authorization code grant flow](#authorization-code-grant-flow) (not recommended)

2. Turn on future flag `unstable_tokenExchange` when configuring shopifyApi

```ts
shopifyApi({
...
isEmbeddedApp: true,
future: {
unstable_tokenExchange: true,
},
})
```
3. Start the OAuth process by calling [shopify.auth.tokenExchange](../reference/auth/tokenExchange.md) to exchange user session token to access token.
4. Use the exchanged session token to make authenticated API queries, see [After OAuth](#after-oauth)
2. Start the token acquisition process by calling [shopify.auth.tokenExchange](../reference/auth/tokenExchange.md) to exchange user session token to access token.
3. Use the exchanged session token to make authenticated API queries, see [After OAuth](#after-oauth)

#### Detecting scope changes

Expand Down
4 changes: 0 additions & 4 deletions packages/shopify-api/future/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
* Future flags are used to enable features that are not yet available by default.
*/
export interface FutureFlags {
/**
* Enable the token exchange OAuth flow.
*/
unstable_tokenExchange?: boolean;
/**
* Enable line item billing, to make billing configuration more similar to the GraphQL API.
*/
Expand Down
5 changes: 3 additions & 2 deletions packages/shopify-api/lib/__tests__/test-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ type TestConfig<Overrides extends TestOverridesOption<Future>, Future> = Modify<
* This way, we'll always ensure our tests are covering all future flags. Please make sure to also have tests for the
* old behaviour.
*/
const TEST_FUTURE_FLAGS: Required<{[key in keyof FutureFlags]: true}> = {
const TEST_FUTURE_FLAGS: Required<{
[key in keyof FutureFlags]: true;
}> = {
v10_lineItemBilling: true,
unstable_tokenExchange: true,
} as const;

const TEST_CONFIG = {
Expand Down
17 changes: 6 additions & 11 deletions packages/shopify-api/lib/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {ConfigInterface} from '../base-types';
import {FeatureEnabled, FutureFlagOptions} from '../../future/flags';

import {OAuthBegin, OAuthCallback, begin, callback} from './oauth/oauth';
import {Nonce, nonce} from './oauth/nonce';
Expand All @@ -14,30 +13,26 @@ import {TokenExchange, tokenExchange} from './oauth/token-exchange';

export function shopifyAuth<Config extends ConfigInterface>(
config: Config,
): ShopifyAuth<Config['future']> {
): ShopifyAuth {
const shopify = {
begin: begin(config),
callback: callback(config),
nonce,
safeCompare,
getEmbeddedAppUrl: getEmbeddedAppUrl(config),
buildEmbeddedAppUrl: buildEmbeddedAppUrl(config),
} as ShopifyAuth<Config['future']>;

if (config.future?.unstable_tokenExchange) {
shopify.tokenExchange = tokenExchange(config);
}
tokenExchange: tokenExchange(config),
} as ShopifyAuth;

return shopify;
}

export type ShopifyAuth<Future extends FutureFlagOptions> = {
export interface ShopifyAuth {
begin: OAuthBegin;
callback: OAuthCallback;
nonce: Nonce;
safeCompare: SafeCompare;
getEmbeddedAppUrl: GetEmbeddedAppUrl;
buildEmbeddedAppUrl: BuildEmbeddedAppUrl;
} & (FeatureEnabled<Future, 'unstable_tokenExchange'> extends true
? {tokenExchange: TokenExchange}
: Record<string, never>);
tokenExchange: TokenExchange;
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,4 @@ describe('tokenExchange', () => {
).rejects.toThrow(ShopifyErrors.InvalidJwtError);
});
});

describe('with future flag disabled', () => {
test('shopifyAuth object does not have tokenExchange property', () => {
const shopify = shopifyApi(
testConfig({
future: {
unstable_tokenExchange: false,
},
}),
);

expect(shopify.auth).not.toHaveProperty('tokenExchange');
});
});
});
4 changes: 2 additions & 2 deletions packages/shopify-api/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export * from './flow/types';
export interface Shopify<
Params extends ConfigParams = ConfigParams,
Resources extends ShopifyRestResources = ShopifyRestResources,
Future extends FutureFlagOptions = FutureFlagOptions,
_Future extends FutureFlagOptions = FutureFlagOptions,
> {
config: ConfigInterface<Params>;
clients: ShopifyClients;
auth: ShopifyAuth<Future>;
auth: ShopifyAuth;
session: ShopifySession;
utils: ShopifyUtils;
webhooks: ShopifyWebhooks;
Expand Down

0 comments on commit 19eedf8

Please sign in to comment.