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

Commit 39f1623

Browse files
authored
Merge pull request #203 from Shopify/beginAuth-set-online-sessions
Change beginAuth sessions default to online
2 parents f736bd1 + be7fe0f commit 39f1623

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
1010
### Fixed
1111

1212
- Don't include extra params when calculating local hmac [#196](https://github.com/Shopify/shopify-node-api/pull/196)
13+
- [Breaking] Change default for OAuth.beginAuth to online sessions [#203](https://github.com/Shopify/shopify-node-api/pull/203)
1314
- [Breaking] Return and delete session in `validateAuthCallback` [#217](https://github.com/Shopify/shopify-node-api/pull/217)
1415
- [Breaking] Extract `addHandler` and `getHandler` methods for webhooks out of `register` [#205](https://github.com/Shopify/shopify-node-api/pull/205)
1516

docs/usage/oauth.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ To do that, you can follow the steps below.
66

77
## Add a route to start OAuth
88

9-
The route for starting the OAuth process (in this case `/login`) will use the library's `beginAuth` method. The `beginAuth` method takes in the request and response objects (from the `http` module), along with the target shop _(string)_, redirect route _(string)_, and whether or not you are requesting [online access](https://shopify.dev/concepts/about-apis/authentication#api-access-modes) _(boolean)_. The method will return a URI that will be used for redirecting the user to the Shopify Authentication screen.
9+
The route for starting the OAuth process (in this case `/login`) will use the library's `beginAuth` method. The method will return a URI that will be used for redirecting the user to the Shopify Authentication screen.
10+
11+
| Parameter | Type | Required? | Default Value | Notes |
12+
| --- | --- | :---: | :---: | --- |
13+
| `request` | `http.IncomingMessage` | Yes | - | The HTTP Request. |
14+
| `response` | `http.ServerResponse` | Yes | - | The HTTP Response. |
15+
| `shop` | `string` | Yes | - | A Shopify domain name in the form `{exampleshop}.myshopify.com`. |
16+
| `redirectPath` | `string` | Yes | - | The redirect path used for callback with a leading `/`. The route should be allowed under the app settings. |
17+
| `isOnline` | `bool` | No | `true` | `true` if the session is online and `false` otherwise. |
18+
1019

1120
<details>
1221
<summary>Node.js</summary>
@@ -17,7 +26,7 @@ The route for starting the OAuth process (in this case `/login`) will use the li
1726
if (pathName === '/login') {
1827
// process login action
1928
try {
20-
const authRoute = await Shopify.Auth.beginAuth(request, response, SHOP, '/auth/callback');
29+
const authRoute = await Shopify.Auth.beginAuth(request, response, SHOP, '/auth/callback', false);
2130

2231
response.writeHead(302, { 'Location': authRoute });
2332
response.end();
@@ -47,13 +56,7 @@ http.createServer(onRequest).listen(3000);
4756

4857
```ts
4958
app.get('/login', async (req, res) => {
50-
let authRoute = await Shopify.Auth.beginAuth(
51-
req,
52-
res,
53-
SHOP,
54-
'/auth/callback',
55-
true,
56-
);
59+
let authRoute = await Shopify.Auth.beginAuth(req, res, SHOP, '/auth/callback', false);
5760
return res.redirect(authRoute);
5861
});
5962
```

docs/usage/webhooks.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ app.get('/auth/callback', async (req, res) => {
6565
// this handler is triggered when a webhook is sent by the Shopify platform to your application
6666
};
6767

68-
const currentSession = await Shopify.Utils.loadCurrentSession(
69-
req,
70-
res,
71-
);
68+
const currentSession = await Shopify.Utils.loadCurrentSession(req, res);
7269

7370
// See https://shopify.dev/docs/admin-api/graphql/reference/events/webhooksubscriptiontopic for a list of available topics
7471
const resp = await Shopify.Webhooks.Registry.register({

src/auth/oauth/oauth.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ const ShopifyOAuth = {
3535
* @param redirect Redirect url for callback
3636
* @param isOnline Boolean value. If true, appends 'per-user' grant options to authorization url to receive online access token.
3737
* During final oauth request, will receive back the online access token and current online session information.
38-
* Defaults to offline access.
38+
* Defaults to online access.
3939
*/
4040
async beginAuth(
4141
request: http.IncomingMessage,
4242
response: http.ServerResponse,
4343
shop: string,
4444
redirectPath: string,
45-
isOnline = false,
45+
isOnline = true,
4646
): Promise<string> {
4747
Context.throwIfUninitialized();
4848
Context.throwIfPrivateApp('Cannot perform OAuth for private apps');

src/auth/oauth/test/oauth.test.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,14 @@ describe('beginAuth', () => {
8787
expect(session).toHaveProperty('expires', undefined);
8888
});
8989

90-
test('sets session id and cookie to shop name with "_offline" for offline access requests', async () => {
91-
await ShopifyOAuth.beginAuth(req, res, shop, '/some-callback');
90+
test('sets session id and cookie to shop name prefixed with "offline_" for offline access requests', async () => {
91+
await ShopifyOAuth.beginAuth(req, res, shop, '/some-callback', false);
9292

9393
expect(cookies.id).toBe(`offline_${shop}`);
9494
});
9595

9696
test('returns the correct auth url for given info', async () => {
97-
const authRoute = await ShopifyOAuth.beginAuth(
98-
req,
99-
res,
100-
shop,
101-
'/some-callback',
102-
);
97+
const authRoute = await ShopifyOAuth.beginAuth(req, res, shop, '/some-callback', false);
10398
const session = await Context.SESSION_STORAGE.loadSession(cookies.id);
10499
/* eslint-disable @typescript-eslint/naming-convention */
105100
const query = {

0 commit comments

Comments
 (0)