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 no plugin supports configuration by getToken when running in Runtime action #33

Closed
duynguyen opened this issue Apr 23, 2020 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@duynguyen
Copy link

I tried getToken method of this lib in a Runtime action, but received an error. Code snippet:

const { context, getToken } = require('@adobe/aio-lib-ims')
const imsContextConfig = {
      client_id: params.clientId,
      client_secret: params.clientSecret,
      techacct: params.techAcct,
      meta_scopes: params.metaScopes,
      ims_org_id: params.orgId,
      private_key: params.privateKey
}
await context.set('my_ctx', imsContextConfig)
const token = await getToken('my_ctx')

This worked when I ran in local node environment, but when running in a Runtime action, it gave an error:

error: Cannot generate token because no plugin supports configuration

I enabled the debug logs in the lib by placing process.env.DEBUG='@adobe/aio-lib-ims*' in the first line of my action code (before requiring @adobe/aio-lib-ims), and this is what I got:

2020-04-23T09:56:05.280Z       stdout: 2020-04-23T09:56:05.280Z @adobe/aio-lib-ims/token-helper getTokenIfValid(token=undefined)
2020-04-23T09:56:05.281Z       stdout: 2020-04-23T09:56:05.281Z @adobe/aio-lib-ims/token-helper _generateToken(reason=Error: Token missing or expired, force=false)
2020-04-23T09:56:05.281Z       stdout: 2020-04-23T09:56:05.281Z @adobe/aio-lib-ims/context get plugins
2020-04-23T09:56:05.281Z       stdout: 2020-04-23T09:56:05.281Z @adobe/aio-lib-ims/config/cli set($plugins)
2020-04-23T09:56:05.281Z       stdout: 2020-04-23T09:56:05.281Z @adobe/aio-lib-ims/token-helper   > Trying: @adobe/aio-lib-ims-oauth/src/ims-cli
2020-04-23T09:56:05.290Z       stdout: 2020-04-23T09:56:05.290Z @adobe/aio-lib-ims/token-helper   > Ignoring failure loading or calling plugin @adobe/aio-lib-ims-oauth/src/ims-cli: { Error: Cannot find module '@adobe/aio-lib-ims-oauth/src/ims-cli' at webpackEmptyContext (/nodejsAction/XXpdBGPj/index.js:175400:10) at Object._generateToken (/nodejsAction/XXpdBGPj/index.js:156564:65) at process._tickCallback (internal/process/next_tick.js:68:7) code: 'MODULE_NOT_FOUND' }
2020-04-23T09:56:05.290Z       stdout: 2020-04-23T09:56:05.290Z @adobe/aio-lib-ims/token-helper   > Trying: @adobe/aio-lib-ims-jwt
2020-04-23T09:56:05.290Z       stdout: 2020-04-23T09:56:05.290Z @adobe/aio-lib-ims/token-helper   > Ignoring failure loading or calling plugin @adobe/aio-lib-ims-jwt: { Error: Cannot find module '@adobe/aio-lib-ims-jwt' at webpackEmptyContext (/nodejsAction/XXpdBGPj/index.js:175400:10) at Object._generateToken (/nodejsAction/XXpdBGPj/index.js:156564:65) at process._tickCallback (internal/process/next_tick.js:68:7) code: 'MODULE_NOT_FOUND' }
2020-04-23T09:56:05.290Z       stdout: 2020-04-23T09:56:05.290Z @adobe/aio-lib-ims/token-helper   > Trying: @adobe/aio-lib-ims-oauth
2020-04-23T09:56:05.290Z       stdout: 2020-04-23T09:56:05.290Z @adobe/aio-lib-ims/token-helper   > Ignoring failure loading or calling plugin @adobe/aio-lib-ims-oauth: { Error: Cannot find module '@adobe/aio-lib-ims-oauth' at webpackEmptyContext (/nodejsAction/XXpdBGPj/index.js:175400:10) at Object._generateToken (/nodejsAction/XXpdBGPj/index.js:156564:65) at process._tickCallback (internal/process/next_tick.js:68:7) code: 'MODULE_NOT_FOUND' }
@meryllblanchet meryllblanchet added the bug Something isn't working label Apr 23, 2020
@shazron
Copy link
Member

shazron commented Apr 23, 2020

This is because of webpack replacing the dynamic require with its own. During compile time, webpack does not know of our dynamic imports at:

const { supports, imsLogin } = require(imsLoginPlugin)

See the method for the fix here: https://stackoverflow.com/a/53074814/219684
In essence, we force a native require in the .js file affected.

@sarahxxu
Copy link

@purplecabbage do you think the work you are doing on webpack reconfiguration can be leveraged to fix this issue?
If not, I think forcing the native require in the short run is the way to go bc we want to make sure headless app using this lib would work as expected.

@moritzraho moritzraho assigned moritzraho and unassigned shazron Apr 29, 2020
@moritzraho
Copy link
Member

moritzraho commented Apr 29, 2020

@sarahxxu yes this could be fixed with a custom webpack config, but I think in this case, as we own the package, it should work with our default build config without any additional config.
As @shazron suggested this can probably be fixed in aio-lib-ims itself

@moritzraho
Copy link
Member

moritzraho commented Apr 30, 2020

When building the library with webpack we need to include the default plugins in the bundle, an easy way to do this is to require them statically in aio-lib-ims: e.g. require('@adobe/aio-lib-ims-jwt'), require('@adobe/aio-lib-ims-oauth')
User provided plugins should be required outside of the webpack context as those are external to the bundle this can be done using @shazron suggestion: const actualRequire = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require

However, after a discussion with @shazron, this goes a bit deeper:

  • Ideally we would need to choose which default plugin to add to the bundle, as for example the oauth plugin as it is now (spawns a server and requires user interaction) does not make sense in a headless context.

@moritzraho
Copy link
Member

cc. @shazron this would be fixed if we get rid of the dynamic requires

@shazron
Copy link
Member

shazron commented Jul 13, 2020

Filed #53 (internal bug is in that issue)

@shazron
Copy link
Member

shazron commented Jul 14, 2020

PR filed #54

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

5 participants