Git Product home page Git Product logo

aio-lib-ims's Introduction

Adobe I/O IMS Library

Version Downloads/week Node.js CILicense Codecov Coverage

The Adobe I/O IMS Library helps interacting with the IMS API as well as creating and invalidating tokens. To support multiple use cases and environments, there is not a single configuration managed by this library but multiple configurations called IMS configuration contexts. Each configuration context holds configuration data needed to create tokens. See the Configuration section below.

Installation

To install the Adobe I/O IMS Library, simply use npm:

npm install @adobe/aio-lib-ims --save

Quickstart

Before using the AIO IMS Library you need to create an integration on Adobe Developer Console from where you can the grab the integration details to setup a first configuration context. Let's use an OAuth2 integration as an example:

const { context, getToken, getTokenData } = require('@adobe/aio-lib-ims')

const config = {
  redirect_uri: "https://callback.example.org",
  client_id: "123456cafebabe",
  client_secret: "12345678-cafe-babe-cafe-9999",
  scope: "openid"
};
await context.set('example', config, true)

const token = await getToken('example')
const tokenDecoded = getTokenData(token)

See the API Documentation for full details.

Configuration

The AIO IMS Library transparently maintains the login configuration and keep access and refresh tokens for reuse before they expire.

All configuration is stored in a single ims root property.

The library supports maintaining multiple configurations for different use cases. Each such configuration is stored in its own named object with the ims configuration. Such a configuration is called an IMS (configuration) context and has a label which allows to refer to the configuration by name.

Here is an example ims configuration

{
  ims: {
    contexts: {
      sample_jwt: {
        client_id: "<jwt-clientid>",
        client_secret: "XXX",
        technical_account_id: "<guid>@techacct.adobe.com",
        meta_scopes: [
          "ent_dataservices_sdk"
        ],
        ims_org_id: "<org-guid>@AdobeOrg",
        private_key: "XXX"
      },
      sample_oauth2: {
        redirect_uri: "https://callback.example.com",
        client_id: "<oauth2-clientid>",
        client_secret: "XXX",
        scope: "openid AdobeID"
      },
    }
  }
}

Running on a Desktop

When running on your local machine the AIO IMS is leveraging the Configuration module for use by aio-cli plugins to load and update the configuration stored in .aio and .env files. The library supports both local and global aio configurations.

Here is an example that relies on the AIO IMS to generate a token from an existing configuration:

const { context, getToken } = require('@adobe/aio-lib-ims')

await context.setCurrent('my-config')
const token = await getToken('my-config')

Running in an Adobe I/O Runtime action

Note that Adobe Developer App Builder applications should not own the responsibility to generate their own IMS access tokens. We strongly discourage this approach in favor of more secure implementation patterns that are documented in our App Builder Security Guide.

The AIO IMS Library can also be used in an Adobe I/O Runtime action. In this case the IMS configuration must be set beforehand. The library is relying on the Adobe I/O Cloud State Library to persist the access tokens across action invocations and reduce the number of requests to IMS.

Here is an Adobe I/O Runtime action example that leverages the AIO IMS:

const { context, getToken } = require('@adobe/aio-lib-ims')

function main ({ imsContextConfig, ...params }) {
  // the IMS context configuration is passed as an action parameter
  // imsContextConfig = { client_id, client_secret, technical_account_id, meta_scopes, ims_org_id, private_key }
  await context.set('my_ctx', imsContextConfig)

  const token = await getToken('my_ctx')
}

Note that setting local=true in context.set('my_ctx', imsContextConfig, true) will not have any effect here.

Also note that internally tokens are cached for a single I/O Runtime action only, this means that cached tokens can't be retrieved across actions and running getToken in another action with the same context name will regenerate a new token. Instead, we recommend using a single I/O Runtime non-web action annotated with that is responsible for generating the token and passing it to other web actions, which then can use the token to integrate with one or several Adobe APIs. In this way, a single action generates the token, effectively (re-)using the cache.

IMS Environment

The use of IMS environments is reserved to Adobe use. For information it is indicated by the env configuration context property and takes one of the values prod and stage. The default value is prod. In general, you do not need to deal with this property.

Set Current Context (Advanced)

The default context can be set locally with await context.setCurrent('contextname'). This will write the following configuration to the ims key in the .aio file of the current working directory:

  ims {
    config: {
      current: "contextname"
    }
  }

If running the library in the same working directory, then getToken can be called without passing the contextname:

await context.set('contextname', config, true)
await context.setCurrent('contextname')
const token = await getToken() // generate a token for the config in the 'contextname' context

Please note that context.setCurrent rewrites the local configuration and replaces the default aio CLI OAuth configuration in a desktop environment. This will break aio commands that run from the same directory. You can revert to the original behaviour by executing aio config delete ims.config.current from that directory.

JWT Configuration (Deprecated)

The JWT configuration has been deprecated in favor of the OAuth Server-to-Server Configuration.

JWT (service to service integration) configuration requires the following properties:

Property Description
client_id The IMS (Oauth2) Client ID. This is the API Key in the integration overview of the Adobe Developer Console.
client_secret The IMS (OAUth2) Client Secret
technical_account_id The Technical Account ID from the integration overview screen in the Adobe Developer Console
meta_scopes An array of meta scope names. These are the labels of one ore more special properties in the sample JWT payload. They can be found in the JWT tab of the Adobe Developer Console integration in the JWT payload properties of the form "https://<ims-host>/s/ent_dataservices_sdk": true,. There may be one or more of depending on the services to which the integration is subscribed. The values to list in the meta_scopes property are the last segment of the URL. In the example case, this would be ent_dataservices_sdk.
ims_org_id The Organization ID from the integration overview screen in the Adobe Developer Console.
private_key The private key matching any one of the Public Keys of the integration. This can be the private key all in one line as a string, or an array of strings (each element is a line from the key file) See the Setting the Private Key section.
passphrase (Optional). The passphrase of the private key.

Setting the Private Key

For a JWT configuration, your private key is generated in Adobe Developer Console, and is downloaded to your computer when you generate it.

Adobe Developer Console does not keep the private key (only your corresponding public key) so you will have to set the private key that was downloaded manually in your IMS context configuration.

You can set your private key in the config via two ways:

  1. Import the private key as a string
  2. Set a file reference to the private key

The instructions below assume a private key file called private.key and CONTEXT_NAME is the name of your JWT context.

  1. To import your private key as a string: aio config:set ims.contexts.CONTEXT_NAME.private_key path/to/your/private.key --file
  2. To set a file reference to the private key instead: aio config:set ims.contexts.CONTEXT_NAME.private_key path/to/your/private.key

Note that the path to your private key, if it is a relative path, will be resolved relative to the current working directory.

OAuth2 Configuration

OAuth2 configuration requires the following properties:

Property Description
client_id The IMS (Oauth2) Client ID. This is the API Key in the integration overview of the Adobe Developer Console.
client_secret The IMS (OAUth2) Client Secret
redirect_uri The Default redirect URI from the integration overview screen in the Adobe Developer Console. Alternatively, any URI matching one of the Redirect URI patterns may be used.
scope Scopes to assign to the tokens. This is a string of comma separated scope names which depends on the services this integration is subscribed to. Adobe Developer Console does not currently expose the list of scopes defined for OAuth2 integrations, a good list of scopes by service can be found in OAuth 2.0 Scopes. At the very least you may want to enter openid.

OAuth Server-to-Server Configuration

This configuration is to replace the JWT Configuration.

OAuth Server-to-Server (client credentials grant type) configuration requires the following properties:

Property Description
client_id The IMS (Oauth2) Client ID. This is the API Key in the integration overview of the Adobe Developer Console.
client_secrets An array of IMS (OAUth2) client secrets
technical_account_email The Technical Account Email from the integration overview screen in the Adobe Developer Console
technical_account_id The Technical Account ID from the integration overview screen in the Adobe Developer Console
scopes Scopes to assign to the tokens. This is an array of strings which depends on the services this integration is subscribed to. The list of scopes defined for the OAuth2 Server-to-Server credential is listed under the Scopes tab for the credential in Adobe Developer Console.
ims_org_id The Organization ID from the integration overview screen in the Adobe Developer Console.

Token Validation

Caching

Validations and invalidations can be cached to improve performance. To use caching, configure a new cache and pass it to the library during initialization:

const { Ims, ValidationCache, getToken} = require('@adobe/aio-lib-ims')

const CACHE_MAX_AGE_MS = 5 * 60 * 1000 // 5 minutes
const VALID_CACHE_ENTRIES = 10000
const INVALID_CACHE_ENTRIES = 20000
const cache = new ValidationCache(CACHE_MAX_AGE_MS, VALID_CACHE_ENTRIES, INVALID_CACHE_ENTRIES)
const ims = new Ims('prod', cache)

const token = params.theToken // May be passed via header, parameter, or other input
const imsValidation = await ims.validateToken(token)
if (!imsValidation.valid) {
  return new Error('Forbidden: This is not a valid IMS token!') // Next time validateToken() is called with this token, a call to IMS will not be made while the cache is still fresh
}

Allow List

You can validate a token against an allow-list of IMS clients. To use an allow-list, pass your token and an array of IMS clients to validateTokenAllowList():

const { Ims } = require('@adobe/aio-lib-ims')
const ims = new Ims()

const token = params.theToken // May be passed via header, parameter, or other input
const allowList = ['ironmaiden', 'metallica', 'gunsandroses']
const imsValidation = await ims.validateTokenAllowList(token, allowList)
if (!imsValidation.valid) {
  return new Error('Forbidden: This client is not allowed!')
}

Contributing

Contributions are welcomed! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.

aio-lib-ims's People

Contributors

amulyakashyap09 avatar arjuncooliitr avatar bisswanger avatar bobvanmanen avatar dependabot[bot] avatar florind12 avatar fmeschbe avatar greenkeeper[bot] avatar justinedelson avatar meryllblanchet avatar michaelgoberling avatar moritzraho avatar purplecabbage avatar sandeep-paliwal avatar shazron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aio-lib-ims's Issues

Ims.validateToken passes invalid token_type field, causes valid tokens to be rejected

Describe the bug

The Ims.validateToken method passes the wrong field, token_type, instead of type to the IMS API. This causes certain JWTs to be rejected.

To Reproduce

Steps to reproduce the behavior:

  1. Go to https://console.adobe.io
  2. Create a new integration
  3. Use the private key and related information to create a JWT
  4. Pass this JWT to the Ims.validateToken API

Expected behavior

The call should succeed, but it fails with this error:

400 - {"error_description": "Type parameter is required!", "error": "invalid_parameter_value"}

Link to missing documentation for forced IMS Login

Describe the bug

On https://github.com/adobe/aio-lib-ims/blob/master/api.md#module_@adobe/aio-lib-ims.getToken, there's a sentence:

See Forced imsLogin for more information on this flag.

Where "Forced imsLogin" is a link to https://github.com/adobe/aio-lib-ims/blob/master/README.md#forced-imslogin, but that anchor is not present in the README.

To Reproduce

Go to the API Documentation. Click the link

Expected behavior

Unclear to me what is intended to be documented. I suppose some definition of what "forced" means.

use new ims config, formerly $ims

README.md:50:All configuration is stored in a single `$ims` root property.
README.md:53:Each such configuration is stored in its own named object with the `$ims` configuration.
README.md:57:Inside the `$ims` configuration object, the name of the _current context_ is stored in the `$current` property.
README.md:59:Here is an example `$ims` configuration
README.md:63:  $ims: {
README.md:226:Additional plugins must be `npm install`-ed and listed in the `$ims/$plugins` array property.
src/context.js:25:const IMS = '$ims'
test/context.test.js:31:  expect(ctx.IMS).toEqual('$ims')
test/token-helper.test.js:23:    // prefix $ims. to all the keys
test/token-helper.test.js:26:        [`$ims.${key}`]: context[key]
test/token-helper.test.js:36:    '$ims.$plugins': imsPlugin ? [imsPlugin] : null

See adobe/aio-cli-plugin-auth#43 for new format

Add back configurable access token creation plugin support

Is your feature request related to a problem? Please describe.
IMS access token creation currently only supports JWT based, OAuth2, and CLI access tokens. Other access token types might be added in the future. So it would be beneficial to add back configurable token creation plugin support to add more types of access token creation.

Describe the solution you'd like

  • Expose API in the Context class to retrieve and update additional token creation plugins
  • Add support to the token generation function to consider the configured token creation plugins in the selection process

Describe alternatives you've considered
n/a

Additional context
n/a

Support for IMS service token generation plugin

curl --location --request POST 'https://ims-na1-stg1.adobelogin.com/ims/token/v1' \
--header 'Content-Type:  application/x-www-form-urlencoded' \
--form 'grant_type=authorization_code' \
--form 'client_id=<your service client Id>' \
--form 'client_secret=<your client secret>' \
--form 'scope=<scopes> \
--form 'code=<your permanent auth code>'

access_token is stored in global conf not local .aio

Expected Behaviour

If I set a local context the access_token should be stored in local config file .aio

Actual Behaviour

local context get rewritten to global config and access_token is stored there

Reproduce Scenario (including but not limited to)

If a user has access to multiple programs he cannot switch the programs as long as the old access_token is stored in the global config file. This is irritating when a local config has been setup

Steps to Reproduce

Create a local config for programA with

aio config:set ims.contexts.aio-cli-plugin-cloudmanager PATH_TO_CONFIG_JSON_FILE --file --json --local
aio config:set ims.contexts.aio-cli-plugin-cloudmanager.private_key PATH_TO_PRIVATE_KEY_FILE --file --local

execute a command within /programmA

aio cloudmanager:list-programs

check for the access_token in .aio

Platform and Version

❯ aio info                                                                                                                                                                                      18:25:30

  System:
    OS: macOS 11.2.2
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 24.42 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.20.1 - ~/.nvm/versions/node/v12.20.1/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.10 - ~/.nvm/versions/node/v12.20.1/bin/npm
  Virtualization:
    Docker: 20.10.5 - /usr/local/bin/docker
  npmGlobalPackages:
    @adobe/aio-cli: 6.0.0
  CLI plugins:
    @adobe/aio-cli 6.0.0 (core)
    @adobe/aio-cli-plugin-app 6.0.0 (core)
    @adobe/aio-cli-plugin-auth 2.4.0 (core)
    @adobe/aio-cli-plugin-certificate 0.2.1 (core)
    @adobe/aio-cli-plugin-cloudmanager 1.3.5 (user)
    @adobe/aio-cli-plugin-config 2.3.0 (core)
    @adobe/aio-cli-plugin-console 3.2.0 (core)
    @adobe/aio-cli-plugin-events 1.1.0 (core)
    @adobe/aio-cli-plugin-info 1.1.1 (core)
    @adobe/aio-cli-plugin-runtime 3.1.0 (core)
    @oclif/plugin-autocomplete 0.3.0 (core)
    @oclif/plugin-help 2.2.3 (core)
    @oclif/plugin-not-found 1.2.4 (core)
    @oclif/plugin-plugins 1.9.5 (core)
    @oclif/plugin-warn-if-update-available 1.7.0 (core)

Sample Code that illustrates the problem

Logs taken while reproducing problem

if a different program defined in .aio wants to be accessed the access_token in global config prevents it:
› aio cloudmanager:list-programs
› Error: [CloudManagerSDK:ERROR_LIST_PROGRAMS] Cannot retrieve programs: https://cloudmanager.adobe.io/api/programs (403 Forbidden) - Detail: Profile is not valid (Code: 403025)

webpack build breaks aio-lib-ims in runtime actions

Relates to #33

Description

When invoking an action that use the lateset aio-lib-ims and was deployed via aio app deloy (built with webpack) we get the following error:

    "result": {
      "error": "Initialization has failed due to: Error: Cannot find module '/package.json'\n    at webpackEmptyContext (/nodejsAction/ov9Ltpr6/index.js:126097:10)\n    at checkNodeVersion (/nodejsAction/ov9Ltpr6/index.js:52777:43)\n    at Object.<anonymous> (/nodejsAction/ov9Ltpr6/index.js:52783:1)\n    at Object.module.exports.Object.defineProperty.value (/nodejsAction/ov9Ltpr6/index.js:52793:30)\n    at __webpack_require__ (/nodejsAction/ov9Ltpr6/index.js:21:30)\n    at Object.module.exports.webpackEmptyContext.keys (/nodejsAction/ov9Ltpr6/index.js:125795:19)\n    at __webpack_require__ (/nodejsAction/ov9Ltpr6/index.js:21:30)\n    at Object.module.exports.Object.defineProperty.value (/nodejsAction/ov9Ltpr6/index.js:51875:36)\n    at __webpack_require__ (/nodejsAction/ov9Ltpr6/index.js:21:30)\n    at Object.<anonymous> (/nodejsAction/ov9Ltpr6/index.js:49883:17)"
    },

The same error appears if we unzip dist/myaction.zip and import the index.js in a node REPL

Reproduce

  • aio app init -> select only actions
  • npm install @adobe/aio-lib-ims
  • require the lib in the action
  • aio app deploy
  • invoke the action => ERROR

Workaround (partial)

use aio-lib-ims 4.0.1 to access the Ims object, getToken won't work because of #33

What causes the error

In 4.0.1...4.1.0#diff-d8c50dc3673a2b383c6c1a0a0c19799fR17-R19, removing the import to const imsCliPlugin = require('@adobe/aio-lib-ims-oauth/src/ims-cli') and const imsOAuthPlugin = require('@adobe/aio-lib-ims-oauth') fixes the problem

Provide an unsetCurrentContext method ?

Relates to #61

Provide a way to programmatically delete the ims.config.current config without having to use aio-lib-config.
This can be used to reset the context back to the default CLI context in a desktop environment

We should also expose this in the auth plugin

getSusiUrl should allow defaults

getSusiUrl should NOT require scope, or redirect_url
both of these values CAN have default registered values in IMS
Currently if we pass scope:null, or callbackUrl:null to this function, it will add &scope=null to the url which will fail.

better error message for context token generation

Right now, if your context does not support the properties needed for the OAuth, or JWT IMS plugins, it will show this error:
Error: cannot generate token because no plugin supports configuration

This error is not very descriptive. There is more info when prefixing this environment variable DEBUG=@adobe/aio-lib-ims:token-helper before your command.

The IMS plugins do check for missing keys, and we can expose the missing keys in aio-lib-ims for reporting: https://github.com/adobe/aio-lib-ims-jwt/blob/f5028aa800c41f53aac663c4ccdcbae4c672263c/src/ims-jwt.js#L39

The issue is, if it is missing properties for a plugin, that's ok, it can match for another plugin. If it does not match all plugins, we need to print out the error message for all the plugins (missing key(s)), so the user can see and filter for themselves.

Expected

When an ims context does not match any IMS plugin, this error is shown:

context properties: ['...']
@adobe/aio-lib-ims-jwt: missing keys(s) ['private_key']
@adobe/aio-lib-ims-oauth: missing keys(s) ['scope', 'redirect_uri' ]

Actual

When an ims context does not match any IMS plugin, this error is shown:
Error: cannot generate token because no plugin supports configuration

An in-range update of codecov is breaking the build 🚨

The devDependency codecov was updated from 3.6.4 to 3.6.5.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

codecov is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Commits

The new version differs by 2 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

token invalidation outside of a single lib core ims context is not handled

Describe the bug
If I have a context configuration that holds an access_token and/or refresh_token and that it gets invalidate outside of this context, then on the next getToken, as long as the token is not expired it will be returned although it's invalid.

This applies for both action and cli config

Reproduce

const { Ims, getToken, invalidateToken, context } = require('.')

const config = {
    client_id: "<jwt-clientid>",
    client_secret: "XXX",
    techacct: "<guid>@techacct.adobe.com",
    meta_scopes: [
      "ent_dataservices_sdk"
    ],
    ims_org_id: "<org-guid>@AdobeOrg",
    private_key: "XXX"
}

await context.set('my-ctx', config)
const token = await getToken('my-ctx')

// await invalidateToken('my-ctx') => would delete the token in the config

// but if the token is invalidate elsewhere the token would still be in the config
// example
const ims = new Ims('prod')
await ims.invalidateToken(token, config.clientId, config.clientSecret)

const token2 = await getToken('my-ctx') // would return the same cached token which is invalid
// furthermore now a call to invalidateToken will throw an error as the token is not valid

Possible solution
in every getTokenIfValid call in token-helper.js validate the token against IMS, however this will trigger many more requests and reduces the advantage of caching the token

OAuth Server-to-Server App Builder Error

Describe the bug
App Builder action is making a call to get an IMS token via OAuth Server-to-Server

When invoking an app builder action which has been deployed using aio app run making a call to get an IMS token via OAuth Server-to-Server the script returns the below error:
{ "error": "An error has occurred: IMSLibError: [IMSSDK:CANNOT_GENERATE_TOKEN] Cannot generate token because no plugin supports configuration:\n[plugin:jwt]: [IMSJWTSDK:MISSING_PROPERTIES] JWT not supported due to some missing properties: client_secret,meta_scopes,private_key" }

When the same action is run locally via node ./action/action-name/index.js the action works as expected and a token is returned.

Code being used:

const { context, getToken, getTokenData } = require('@adobe/aio-lib-ims');

async function main(params) {
  const config = {
    client_id: '_redacted_',
    client_secrets: ['_redacted_'],
    ims_org_id: '_redacted_',
    scopes: ['AdobeID', 'openid', 'read_organizations', 'additional_info.projectedProductContext', 'additional_info.roles', 'adobeio_api', 'read_client_secret', 'manage_client_secrets', 'event_receiver_api'],
    technical_account_email: '_redacted_',
    technical_account_id: '_redacted_',
  };
  await context.set('imsToken', config);

  const token = await getToken('imsToken');
  const tokenDecoded = getTokenData(token);
  console.log(token, tokenDecoded);
  return { token, tokenDecoded };
}
exports.main = main;

To Reproduce

  1. Create action which uses @adobe/aio-lib-ims to get a token using OAuth Server-to-Server
  2. Deploy action via aio app run
  3. Invoke aciton via aio rt action invoke *action name* --result
  4. Observe error above

Expected behavior
A token is returned

Use @adobe/aio-lib-core-errors

Is your feature request related to a problem? Please describe.

This library (and aio-lib-ims-jwt and aio-lib-ims-oauth although I'm not yet creating separate issues for those since I'd like to get consensus on this library first) creates Error objects which are hard to distinguish in a programatic way from generic JavaScript Error objects.

Describe the solution you'd like

Errors thrown should use @adobe/aio-lib-core-errors to produce errors with a populated name and sdkName properties specific to this library.

Describe alternatives you've considered

  • Parsing the error message
  • Inspecting the stack trace

Neither of which are really scalable.

Additional context
Add any other context or screenshots about the feature request here.

OAuth Server-to-Server incorrect parameter documentation

Describe the bug
When following OAuth Server-to-Server configuration in the readme an error is returned: [IMSOAuthSDK:MISSING_PROPERTIES] OAuth2 not supported due to some missing properties: technical_account_email,technical_account_id,ims_org_id"

By reading the code in https://github.com/adobe/aio-lib-ims-oauth/blob/master/src/ims-oauth_server_to_server.js it is clear that the properties need to be as follows:

Property Description
client_id The IMS (Oauth2) Client ID. This is the API Key in the integration overview of the Adobe Developer Console.
client_secrets An array of IMS (OAUth2) client secrets
technical_account_email The Technical Account Email from the integration overview screen in the Adobe Developer Console
technical_account_id The Technical Account ID from the integration overview screen in the Adobe Developer Console
scopes Scopes to assign to the tokens. This is an array of strings which depends on the services this integration is subscribed to. The list of scopes defined for the OAuth2 Server-to-Server credential is listed under the Scopes tab for the credential in Adobe Developer Console.
ims_org_id The Organization ID from the integration overview screen in the Adobe Developer Console.

Token generation in Adobe I/O Runtime action: unclear local option for the initial context.set call

The API doc states that setting local=true in the context.set call will disable persistence when running in Runtime actions.

The readme doc shows an initial context.set call to set the JWT configuration and the user might falsely assume that setting local=true in that initial call will disable persistence.

The user however has no control over persistence, because tokens are always persisted during the getToken call, which internally always calls context.set with local=false. See https://github.com/adobe/aio-lib-ims/blob/master/src/token-helper.js#L155

improve e2e tests with retry and exponential fallback

We run the e2e tests daily via the aio-e2e-tests repo. The connection to IMS sometimes fails because we can't exchange a jwt token, and we should be using aio-lib-core-networking to do a retry with fallback.

Test failures:

FAIL e2e/e2e.js
  ✓ init test (4ms)
  ✓ getAccessToken (224ms)
  ✕ exchangeJwtToken (196ms)
  ✕ getTokenData (1ms)
  ✕ getOrganizations (1ms)
    at Function.module.exports.sync (/home/runner/work/aio-e2e-tests/aio-e2e-tests/node_modules/execa/index.js:187:17)
    at runOne (/home/runner/work/aio-e2e-tests/aio-e2e-tests/src/run.js:71:9)
    at /home/runner/work/aio-e2e-tests/aio-e2e-tests/src/run.js:132:9
    at Array.forEach (<anonymous>)
    at runAll (/home/runner/work/aio-e2e-tests/aio-e2e-tests/src/run.js:126:29)
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  command: 'npm run e2e',
  exitCode: 1,
  exitCodeName: 'EPERM',
  stdout: '\n' +
    '> @adobe/[email protected] e2e /home/runner/work/aio-e2e-tests/aio-e2e-tests/.repos/aio-lib-ims\n' +
    '> jest --config e2e/jest.config.js\n',
  stderr: undefined,
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false,
  signal: undefined
}

Consolidate `token-helper` test files into one

Test files:

  1. https://github.com/adobe/aio-lib-ims/blob/master/test/token-helper.test.js
  2. https://github.com/adobe/aio-lib-ims/blob/master/test/token.helper.webpack.test.js

There is a lot of duplication in here, and there exists a test (getTokenWithOptions - string (jwt)) that does not exist in the other, and some minor differences. The only differences should be:

  1. global.WEBPACK_ACTION_BUILD = true (for webpack tests)
  2. getToken (string - cli) test should reject for webpack tests, resolve otherwise
  3. getToken (string - oauth) test should reject for webpack tests, resolve otherwise

The issue is the loading of

const { IMS_TOKEN_MANAGER } = require('../src/token-helper')
which changes its implementation (via the global WEBPACK_ACTION_BUILD) on load.

This can be mitigated by dynamically loading the module and using jest.isolateModules (was only available in Jest 24+): https://jestjs.io/docs/jest-object#jestisolatemodulesfn

Error no plugin supports configuration by `getToken` when running in Runtime action

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' }

An in-range update of eslint-plugin-jest is breaking the build 🚨

The devDependency eslint-plugin-jest was updated from 23.6.0 to 23.7.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Release Notes for v23.7.0

23.7.0 (2020-02-07)

Bug Fixes

Features

  • valid-title: support disallowedWords option (#522) (38bbe93)
Commits

The new version differs by 7 commits.

  • 88068a7 chore(release): 23.7.0 [skip ci]
  • c12b725 fix(expect-expect): use u flag in regex (#532)
  • ff25588 chore(deps): removed dependency on micromatch for expect-expect (#517)
  • 38bbe93 feat(valid-title): support disallowedWords option (#522)
  • 1449675 chore: make gh actions badge always point to master
  • 95cce6b chore(deps): lock file maintenance (#490)
  • 735f143 chore(lint): enable require-unicode-regexp rule (#520)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @adobe/aio-lib-core-config is breaking the build 🚨

The dependency @adobe/aio-lib-core-config was updated from 1.2.0 to 1.2.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@adobe/aio-lib-core-config is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details

Release Notes for path files were not included in package.json
  • fix: patch files were not included ba0cc71

1.2.0...1.2.1

Commits

The new version differs by 2 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of stdout-stderr is breaking the build 🚨

The devDependency stdout-stderr was updated from 0.1.9 to 0.1.10.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

stdout-stderr is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

jwt passphrase - provide a way to set passphrase without storing it in the context config on disk

The private key passphrase should not be stored in the config on disk, but the aio-lib-ims-jwt ims plugin requires it as a property on the context to unlock the private key. This is not secure. The passphrase is often a transient value provided as a flag via the CLI.

We need a way to:

  1. use an in-memory-context config that can be modified without it being written to disk (so you can set the passphrase property, for example)
  2. getToken should use this in-memory-context config

An in-range update of @adobe/eslint-config-aio-lib-config is breaking the build 🚨

The devDependency @adobe/eslint-config-aio-lib-config was updated from 1.0.2 to 1.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@adobe/eslint-config-aio-lib-config is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Release Notes for Add jsdoc plugin, tests and travis
  • fix: add test, .travis.yml file (closes #2, closes #3) 76753d0

1.0.2...1.1.0

Commits

The new version differs by 2 commits.

  • ff9a9f1 1.1.0
  • 76753d0 fix: add test, .travis.yml file (closes #2, closes #3)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

documentation needed for new config changes

Describe the bug
The new config changes lack documentation in the README - short blurb maybe on how it will work in cli versus an action.
The new API changes need to be reflected in the README as well.

Rename to aio-lib-core-ims

@fmeschbe Ok if I rename it to aio-lib-core-ims and change all references in the other repos?
(similar request for the other libraries with aio-cna-core in the name)

fix: remove support for ims plugins

Currently, all IMS plugins that are used are hardcoded, and there is no current use case to dynamically load and use an ims plugin.

To specify an ims plugin, you would add the plugin package name in the ims.config.plugins array. Even if you added the plugin in the config, during runtime node may have trouble resolving where the plugin is, and you will have to add where it is by appending to the NODE_PATH environment variable.

Also, the dynamic nature of resolving ims plugins is causing problems with webpack and Adobe I/O Runtime functions. See #33.

Listing contexts without configuration yields TypeError

Describe the bug
Running aio auth:ctx --list without configuration yields:

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at CliConfig.contexts (/usr/local/lib/node_modules/@adobe/aio-cli/node_modules/@adobe/aio-lib-ims/src/config/cli.js:48:19)
    at Context.keys (/usr/local/lib/node_modules/@adobe/aio-cli/node_modules/@adobe/aio-lib-ims/src/context.js:189:25)
    at CtxCommand.run (/usr/local/lib/node_modules/@adobe/aio-cli/node_modules/@adobe/aio-cli-plugin-auth/src/commands/auth/ctx.js:22:38)
    at CtxCommand._run (/usr/local/lib/node_modules/@adobe/aio-cli/node_modules/@oclif/command/lib/command.js:44:31)

To Reproduce
Steps to reproduce the behavior:

  1. Launch empty NodeJS 10 docker container: docker run --rm -it node:10-alpine /bin/sh
  2. Clean install aio CLI version 3.2.0: npm install -g @adobe/aio-cli
  3. Run aio auth:ctx --list
  4. See error

Expected behavior
No output

Screenshots
n/a (see dump in the description)

Desktop (please complete the following information):

# aio -v
@adobe/aio-cli/3.2.0 linux-x64 node-v10.19.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.