Created
April 3, 2023 13:23
-
-
Save cfjedimaster/54fbfc2c4a8e90ffda5f6007ddb13714 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fetch from 'node-fetch'; | |
import jwt from 'jsonwebtoken'; | |
const { sign, verify } = jwt; | |
export default defineComponent({ | |
async run({ steps, $ }) { | |
const key = process.env.PSAPI_KEY; | |
const CLIENT_ID = process.env.PSAPI_CLIENTID; | |
const CLIENT_SECRET = process.env.PSAPI_CLIENTSECRET; | |
const TECHNICAL_ACCOUNT_ID = process.env.PSAPI_TECHNICALACCOUNTID; | |
const ORGANIZATION_ID = process.env.PSAPI_ORGANIZATIONID; | |
const jwtOptions = { | |
"iss": ORGANIZATION_ID, | |
"sub": TECHNICAL_ACCOUNT_ID, | |
"https://ims-na1.adobelogin.com/s/ent_ccas_sdk": true, | |
"aud": `https://ims-na1.adobelogin.com/c/${CLIENT_ID}` | |
} | |
const token = sign(jwtOptions, key, {expiresIn: 300, algorithm: 'RS256'}) | |
let atBody = `client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&jwt_token=${token}`; | |
let getATReq = await fetch('https://ims-na1.adobelogin.com/ims/exchange/jwt', { | |
method:'POST', | |
headers: { | |
'Content-Type':' application/x-www-form-urlencoded' | |
}, | |
body: atBody | |
}); | |
let access_token = (await getATReq.json()).access_token; | |
return access_token; | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment