Data Types

BeginAuthSessionParams

Parameter object passed to the AuthManager.beginAuthSession(params) method in the Bytescale SDKs.

{
"accountId": "YOUR_ACCOUNT_ID",
"authHeaders": Function,
"authUrl": "https://your-web-app/your-auth-url",
"options": {
"cdnUrl": "https://your-custom-cname"
},
"serviceWorkerScript": "/bytescale-auth-sw.js"
}

Your account ID.

This is visible on the settings page:

https://www.bytescale.com/dashboard/settings

Example: "A623uY2"

Type: String

Length: 7

Parameterless function that returns a Promise containing the HTTP request headers to send to the authUrl (represented as a simple dictionary/object).

You must use this parameter to authorize with your authUrl.

Important: do not call 'AuthManager.beginAuthSession' or 'AuthManager.endAuthSession' inside this callback, as this will cause a deadlock.

Type: Function

The fully-qualified URL for your backend API's auth endpoint (the endpoint that returns a JWT as plain text).

Example: "https://your-web-app/your-auth-url"

Type: String

Min Length: 1

Max Length: 255

Optional parameters for the BeginAuthSessionParams.

Type: BeginAuthSessionParamsOptions

Enables JWT support for modern browsers that block third-party cookies (like Safari).

When this field is set, the AuthManager will use an Authorization header instead of a Cookie header for authenticating your requests by registering a service worker for the page. If the browser does not support service workers, or if this field is not set, session cookies will be used for authentication instead.

Instructions:

Ensure the accountId field is set alongside the exp field in your JWT.

You must create a JavaScript file that contains the following line: importScripts("https://js.bytescale.com/auth-sw/v1");

You must host this JavaScript file under the root directory of your website's domain (e.g. www.example.com not assets.example.com).

You must set the serviceWorkerScript parameter to the absolute path of this script when calling AuthManager.beginAuthSession.

Examples:

Correct: "/bytescale-auth-sw.js"

Incorrect: "bytescale-auth-sw.js"

Incorrect: "/scripts/bytescale-auth-sw.js"

Incorrect: "https://example.com/bytescale-auth-sw.js"

Explanation:

Service workers can only interact with events raised by pages at the same level or below them, hence why your script must be hosted on your website's domain under the root directory.

Troubleshooting:

If requests occasionally fail to authenticate, you may be experiencing a race condition between the Service Worker being ready, and the private files being requested by the browser.

You can address this issue by following the support article below:

https://support.bytescale.com/article/61-troubleshooting-service-worker-authentication-issues

Example: "/bytescale-auth-sw.js"

Type: String

Was this section helpful? Yes No

You are using an outdated browser.

This website requires a modern web browser -- the latest versions of these browsers are supported: