You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+79-49Lines changed: 79 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,28 +2,65 @@
2
2
3
3
A JavaScript library for managing authentication for [Storyblok](https://www.storyblok.com) apps.
4
4
5
+
## Migrating v1 to v2
6
+
7
+
The `@storyblok/app-extension-auth` v1 stored the access token in a cookie. However, in a future version of v2, the library will offer an adapter pattern, allowing you to store the access token elsewhere, such as in a dedicated database. The following breaking changes abstract the code to make this transition easier in the near future:
The `sessionStore` created by `sessionCookieStore` now has three methods: `get`, `put`, and `remove`. The `getAll` method is no longer provided. If you believe the `getAll` method is still useful for your use case, please let us know by opening a GitHub issue.
29
+
30
+
The `put` and `remove` methods now return a `Promise<boolean>` instead of a `Promise<void>`.
Note: the `@storyblok/app-extension-auth` is currently in alpha, and is prone to changes. Therefore, save the [exact version](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#dependencies) to your `package.json` with the commands above.
26
-
27
64
### Set a URL
28
65
29
66
Decide a URL for your app. As a first step, this should be a URL for local development. For this you will need a secure tunnel, for example [ngrok](https://ngrok.com/).
@@ -38,11 +75,11 @@ ngrok http 3000
38
75
39
76
Create an App in Storyblok's Partner Portal. Then open app's settings, navigate to _Oauth 2_, and configure the following values:
40
77
41
-
***URL to your app**: the index page of your app. For example, `https://my-app.com/`.
78
+
-**URL to your app**: the index page of your app. For example, `https://my-app.com/`.
42
79
43
-
***OAuth2 callback URL**: the api endpoint that will initiate the OAuth flow.
Some variables should be loaded via environmental variables (`.env.local`):
67
104
68
-
*`clientId` -- The client ID is a public identifier for your apps. Find the Client ID in the app settings on Storyblok.
69
-
*`clientSecret` -- The client secret is a secret known only to the application and the authorization server. Find the client secret in the app settings on Storyblok.
70
-
71
-
Load it into the application as an environmental variable.
72
-
It must be kept confidential.
73
-
*`baseUrl` -- The base URL specifies the base URL to use for all relative authentication API endpoints created by authHandler().
105
+
-`clientId` -- The client ID is a public identifier for your apps. Find the Client ID in the app settings on Storyblok.
106
+
-`clientSecret` -- The client secret is a secret known only to the application and the authorization server. Find the client secret in the app settings on Storyblok.
107
+
Load it into the application as an environmental variable.
108
+
It must be kept confidential.
109
+
-`baseUrl` -- The base URL specifies the base URL to use for all relative authentication API endpoints created by authHandler().
74
110
The base URL must be absolute and secure with https.
75
-
111
+
76
112
For example, the base URL `https://my-app.my-domain.com/` will create the following api endpoints:
113
+
77
114
-`https://my-app.my-domain.com/storyblok` for initiating the authentication flow
78
115
-`https://my-app.my-domain.com/storyblok/callback` as the OAuth2 callback URL
79
116
80
117
The other variables can be hard-coded:
81
118
82
-
*`successCallback` -- Specifies the URL that the user agent will be redirected to after a _successful_ authentication flow. Defaults to `"/"`.
83
-
*`errorCallback` -- Specifies the URL that the user agent will be redirected to after an _unsuccessful_ authentication flow. If omitted, the user agent will receive a 401 response without redirect.
84
-
*`endpointPrefix` -- Specifies the partial URL that is located between the baseUrl and the
119
+
-`successCallback` -- Specifies the URL that the user agent will be redirected to after a _successful_ authentication flow. Defaults to `"/"`.
120
+
-`errorCallback` -- Specifies the URL that the user agent will be redirected to after an _unsuccessful_ authentication flow. If omitted, the user agent will receive a 401 response without redirect.
121
+
-`endpointPrefix` -- Specifies the partial URL that is located between the baseUrl and the
85
122
authentication API endpoints.
86
123
87
-
For example, the following two properties
88
-
-`baseUrl: "https://my-app.my-domain.com/"`
89
-
-`endpointPrefix: "api/authenticate"`
124
+
For example, the following two properties
125
+
126
+
-`baseUrl: "https://my-app.my-domain.com/"`
127
+
-`endpointPrefix: "api/authenticate"`
128
+
129
+
will result in the API endpoints
90
130
91
-
will result in the API endpoints
92
-
-`https://my-app.my-domain.com/api/authenticate/storyblok` for initiating the authentication flow
93
-
-`https://my-app.my-domain.com/api/authenticate/storyblok/callback` as the OAuth2 callback URL
131
+
-`https://my-app.my-domain.com/api/authenticate/storyblok` for initiating the authentication flow
132
+
-`https://my-app.my-domain.com/api/authenticate/storyblok/callback` as the OAuth2 callback URL
94
133
95
134
### Create an API route
96
135
@@ -110,8 +149,8 @@ Sign in a user by redirecting to the api route: `/api/connect/storyblok`
110
149
111
150
This will initiate the oauth flow and redirect the user to the url specified in the `successCallback` URL. The following query parameters will be appended to the `successCallback` URL:
112
151
113
-
*`userId`
114
-
*`spaceId`
152
+
-`userId`
153
+
-`spaceId`
115
154
116
155
### Retrieve the session
117
156
@@ -123,24 +162,18 @@ import { sessionCookieStore } from '@storyblok/app-extension-auth'
When you redirect the user agent to a new page within your application, you need to _append the `spaceId` and `userId` query parameters_. Only if you do this can you retrieve the session from the `sessionCookieStore` from the other route.
0 commit comments