This library provides core authentication functionality for Adobe I/O SDK libraries and applications.
npm install @adobe/aio-lib-core-authconst { generateAccessToken } = require('@adobe/aio-lib-core-auth')
async function main(params) {
try {
// if the include-ims-credentials annotation is set, the library infers credentials from the Runtime params
const token = await generateAccessToken(params)
// otherwise credentials can be passed manually
const token = await generateAccessToken({
clientId: '<clientId>',
clientSecret: '<clientSecret>',
orgId: '<orgId>@AdobeOrg',
scopes: ['<scope1>', '<scope2>', '..']
})
console.log('Authentication successful:', token.access_token)
} catch (error) {
console.error('Authentication failed:', error)
}
}Note: The token is cached for 5 minutes in the Runtime's container memory. A single Runtime action can run in multiple containers, meaning the cache is not shared across actions.
The library caches tokens for 5 minutes to improve performance. If you need to force a refresh:
const { invalidateCache } = require('@adobe/aio-lib-core-auth')
async function main(params) {
try {
invalidateCache()
} catch (error) {
console.error('Authentication failed:', error)
}
}goto API
Contributions are welcomed! Read the Contributing Guide for more information.
This project is licensed under the Apache V2 License. See LICENSE for more information.