Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ export function invalidateCache () {
* @param {string} params.clientSecret - The client secret
* @param {string} params.orgId - The organization ID
* @param {string[]} [params.scopes=[]] - Array of scopes to request
* @param {string} [imsEnv='prod'] - The IMS environment ('prod' or 'stage')
* @param {string} [imsEnv] - The IMS environment ('prod' or 'stage'); when omitted or falsy, uses stage if __OW_NAMESPACE starts with 'development-', else prod
* @returns {Promise<object>} Promise that resolves with the token response
* @throws {Error} If there's an error getting the access token
*/
export async function generateAccessToken (params, imsEnv = 'prod' ) {
export async function generateAccessToken (params, imsEnv) {
imsEnv = imsEnv || (ioRuntimeStageNamespace() ? 'stage' : 'prod')

const credentials = getAndValidateCredentials(params)

const credAndEnv = { ...credentials, env: imsEnv }
Expand All @@ -74,3 +76,7 @@ export async function generateAccessToken (params, imsEnv = 'prod' ) {

return token
}

function ioRuntimeStageNamespace () {
return process.env.__OW_NAMESPACE && process.env.__OW_NAMESPACE.startsWith('development-')
}
85 changes: 0 additions & 85 deletions test/AuthErrors.test.js

This file was deleted.

Loading