Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@storyblok/app-extension-auth
Advanced tools
A typed JavaScript library for handling authentication with Storyblok apps.
A JavaScript library for managing authentication for Storyblok apps.
See our starters:
Install with npm:
npm install --save-exact @storyblok/app-extension-auth
or with Yarn:
yarn add --exact @storyblok/app-extension-auth
Note: the @storyblok/app-extension-auth
is currently in alpha, and is prone to changes. Therefore, save the exact version to your package.json
with the commands above.
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.
To open a secure tunnel with ngrok, run:
ngrok http 3000
Create an App in Storyblok's Partner Portal. Then open app's settings, navigate to Oauth 2, and configure the following values:
URL to your app: the index page of your app. For example, https://my-app.com/
.
OAuth2 callback URL: the api endpoint that will initiate the OAuth flow.
{baseUrl}/{endpointPrefix}/storyblok/callback
https://my-app.com/api/connect/storyblok/callback
Substitute {baseUrl}
and {endpointPrefix}
for your own values. These parameters will be referenced again in your code; see the next section.
In your source code, create the following object (you will need it later):
import { AuthHandlerParams } from '@storyblok/app-extension-auth'
export const params: AuthHandlerParams = {
clientId: process.env.APP_CLIENT_ID,
clientSecret: process.env.APP_CLIENT_SECRET,
baseUrl: process.env.APP_URL,
successCallback: '/',
errorCallback: '/401',
endpointPrefix: '/api/connect',
}
Some variables should be loaded via environmental variables (.env.local
):
clientId
-- The client ID is a public identifier for your apps. Find the Client ID in the app settings on Storyblok.
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.
Load it into the application as an environmental variable. It must be kept confidential.
baseUrl
-- The base URL specifies the base URL to use for all relative authentication API endpoints created by authHandler().
The base URL must be absolute and secure with https.
For example, the base URL https://my-app.my-domain.com/
will create the following api endpoints:
https://my-app.my-domain.com/storyblok
for initiating the authentication flowhttps://my-app.my-domain.com/storyblok/callback
as the OAuth2 callback URLThe other variables can be hard-coded:
successCallback
-- Specifies the URL that the user agent will be redirected to after a successful authentication flow. Defaults to "/"
.
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.
endpointPrefix
-- Specifies the partial URL that is located between the baseUrl and the
authentication API endpoints.
For example, the following two properties
baseUrl: "https://my-app.my-domain.com/"
endpointPrefix: "api/authenticate"
will result in the API endpoints
https://my-app.my-domain.com/api/authenticate/storyblok
for initiating the authentication flowhttps://my-app.my-domain.com/api/authenticate/storyblok/callback
as the OAuth2 callback URLIn NodeJS, create a dynamic route that handles the incoming requests with authHandler()
. See Framework examples.
For example, in Next.js, create a file pages/api/connect/[...slugs].ts
:
import { authHandler } from '@storyblok/app-extension-auth'
export default authHandler(params)
Sign in a user by redirecting to the api route: /api/connect/storyblok
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:
userId
spaceId
Now, use these two query parameters to retrieve the session object:
import { sessionCookieStore } from '@storyblok/app-extension-auth'
const sessionStore = sessionCookieStore(params)(context)
const appSession = await sessionStore.get(query)
if(appSession === undefined){
// The user is not authenticated
// redirect to /api/connect/storyblok
}
The AppSession
object contain user information for personalized content, and an access token to the Storyblok management API.
const {
userId,
spaceId,
region,
roles,
accessToken
} = appSession
Storyblok apps are embedded within Storyblok via iframes. When a page is requested, the server must get to know
spaceId
: the space the page is being embedded withinuserId
: the user who loaded the pageThese two values needs to be encoded within the page request.
If these two values cannot be retrieved, you need to initiate the OAuth flow by redirecting the user agent to /api/connect/storyblok
. After a successful authentication, the spaceId
and userId
will be added as query parameters to the successCallback
value. Now, it should be possible to retrieve the session like so
import { sessionCookieStore } from '@storyblok/app-extension-auth'
const sessionStore = sessionCookieStore(params)(context)
const appSession = await sessionStore.get(query)
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.
const href = `/my/other/page?spaceId=${spaceId}&userId=${userId}`
In Next.js, create a file pages/api/connect/[...slugs].ts
import { authHandler } from '@storyblok/app-extension-auth'
export default authHandler(params)
In ExpressJs, create a route
import { authHandler } from '@storyblok/app-extension-auth'
app.all(
'/api/connect/*',
authHandler(params)
)
FAQs
A typed JavaScript library for handling authentication with Storyblok apps.
The npm package @storyblok/app-extension-auth receives a total of 0 weekly downloads. As such, @storyblok/app-extension-auth popularity was classified as not popular.
We found that @storyblok/app-extension-auth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.