Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when getting token from context specified in .env #696

Open
obarcelonap opened this issue Nov 29, 2024 · 1 comment
Open

Error when getting token from context specified in .env #696

obarcelonap opened this issue Nov 29, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@obarcelonap
Copy link

Expected Behaviour

When configuring an app to use a workspace using aio app use -m Outh Service 2 Service credentials are persisted in .env file.
Example

AIO_ims_contexts_MyCredentialName_client__id=client-id
AIO_ims_contexts_MyCredentialName_client__secrets=["client-secret"]
AIO_ims_contexts_MyCredentialName_technical__account__email[email protected]
AIO_ims_contexts_MyCredentialName_technical__account__id[email protected]
AIO_ims_contexts_MyCredentialName_scopes=["scope1","scope2"]
AIO_ims_contexts_MyCredentialName_ims__org__id=imsOrg@AdobeOrg

It should be possible to use these credentials from an npm script, which is useful for initializing the application requirements (event providers/metadatas/others)

require('dotenv').config();
const { getToken } = require('@adobe/aio-lib-ims');
...
const accessToken = await getToken('MyCredentialName', {});

Actual Behaviour

It fails with the following error:

/Users/obarcelonapa/dev/test-app-builder/node_modules/@adobe/aio-lib-ims/src/ims.js:391
      scope: scopes.join(',')
                    ^

TypeError: scopes.join is not a function
    at Ims.getAccessTokenByClientCredentials (/Users/obarcelonapa/dev/test-app-builder/node_modules/@adobe/aio-lib-ims/src/ims.js:391:21)
    at /Users/obarcelonapa/dev/test-app-builder/node_modules/@adobe/aio-lib-ims-oauth/src/ims-oauth_server_to_server.js:77:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object._persistTokens (/Users/obarcelonapa/dev/test-app-builder/node_modules/@adobe/aio-lib-ims/src/token-helper.js:156:20)
    at async testGetToken (/Users/obarcelonapa/dev/test-app-builder/scripts/ensure-event-providers.js:49:24)

For the error my assumption is that the IMS context is found and resolved correctly from the env file but it seems the scopes are not parsed as an array, so it fails when trying to join them when preparing the request to the IMS service.

Reproduce Scenario (including but not limited to)

Steps to Reproduce

Platform and Version

@adobe/aio-lib-ims:7.0.2
@adobe/aio-lib-core-config:5.0.1
@adobe/aio-sdk:6.0.0

Sample Code that illustrates the problem

Logs taken while reproducing problem

@shazron shazron added the bug Something isn't working label Nov 29, 2024
@aiojbot
Copy link

aiojbot commented Nov 29, 2024

JIRA issue created: https://jira.corp.adobe.com/browse/ACNA-3388

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants