-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add Ims token for db commands #36
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
Merged
pdohogne-magento
merged 6 commits into
epic/abdb-implementation
from
cext-5606/feat-add-Imstoken-auth
Mar 9, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8091373
feat: add Ims token fetch for db client
AjazSumaiya ab54203
address review comments
AjazSumaiya 123ef3e
refactor: use ims lib for token and context handling
AjazSumaiya 793e5d0
fix: tests
AjazSumaiya 6a492a6
fix: minor
AjazSumaiya 6af65a2
fix: ims context name and address review comments
AjazSumaiya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| Copyright 2026 Adobe. All rights reserved. | ||
| This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. You may obtain a copy | ||
| of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under | ||
| the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| OF ANY KIND, either express or implied. See the License for the specific language | ||
| governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * Helper to get the IMS access token using Adobe I/O SDK | ||
| * @returns {string} The IMS access token | ||
| */ | ||
| import aioLibIms from '@adobe/aio-lib-ims' | ||
| import { CONFIG_IMS_TECHNICAL_ACCOUNT_EMAIL_PLACEHOLDER, CONFIG_IMS_TECHNICAL_ACCOUNT_ID_PLACEHOLDER } from '../constants/global.js' | ||
| const normalizeArrayString = (value) => { | ||
| try { | ||
| const parsed = JSON.parse(value) | ||
| return Array.isArray(parsed) ? JSON.stringify(parsed) : '[]' | ||
| } catch { | ||
| const items = value.split(',').map((entry) => entry.trim()).filter(Boolean) | ||
| return JSON.stringify(items) | ||
| } | ||
| } | ||
|
|
||
| const buildAuthConfig = () => { | ||
| const clientId = process.env.IMS_OAUTH_S2S_CLIENT_ID | ||
| const clientSecret = process.env.IMS_OAUTH_S2S_CLIENT_SECRET | ||
| const orgId = process.env.IMS_OAUTH_S2S_ORG_ID | ||
| const scopes = process.env.IMS_OAUTH_S2S_SCOPES | ||
| const technicalAccountEmail = process.env.IMS_OAUTH_S2S_TECHNICAL_ACCOUNT_EMAIL || CONFIG_IMS_TECHNICAL_ACCOUNT_EMAIL_PLACEHOLDER | ||
| const technicalAccountId = process.env.IMS_OAUTH_S2S_TECHNICAL_ACCOUNT_ID || CONFIG_IMS_TECHNICAL_ACCOUNT_ID_PLACEHOLDER | ||
|
|
||
| if (!clientId || !clientSecret || !orgId || !scopes) { | ||
| throw new Error('Missing required credentials. Please set IMS_OAUTH_S2S_CLIENT_ID, IMS_OAUTH_S2S_CLIENT_SECRET, IMS_OAUTH_S2S_ORG_ID, and IMS_OAUTH_S2S_SCOPES environment variables.') | ||
| } | ||
|
|
||
| return { | ||
| client_id: clientId, | ||
| client_secrets: normalizeArrayString(clientSecret), | ||
| ims_org_id: orgId, | ||
| scopes: normalizeArrayString(scopes), | ||
| technical_account_email: technicalAccountEmail, | ||
| technical_account_id: technicalAccountId | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get or generate an IMS access token using OAuth Server-to-Server credentials. | ||
| * @returns {Promise<string>} The access token | ||
| */ | ||
| export async function getAccessToken () { | ||
| const runtimeNamespace = process.env.AIO_RUNTIME_NAMESPACE | ||
|
|
||
| if (!runtimeNamespace) { | ||
| throw new Error('Runtime namespace is required. Please set AIO_RUNTIME_NAMESPACE environment variable.') | ||
| } | ||
|
|
||
| try { | ||
| const authConfig = buildAuthConfig() | ||
| const imsContextName = `oauth_s2s_${runtimeNamespace}` | ||
|
|
||
| const { context, getToken } = aioLibIms | ||
| await context.set(imsContextName, authConfig, true) | ||
| const accessToken = await getToken(imsContextName) | ||
|
|
||
| if (!accessToken) { | ||
| throw new Error('Failed to generate access token. Please verify your credentials.') | ||
| } | ||
|
|
||
| return accessToken | ||
| } catch (error) { | ||
| if (error instanceof Error) { | ||
| throw error | ||
| } | ||
| throw new Error('Failed to retrieve access token: Unknown error') | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this logic is already handled by
aio-lib-imsplease rewrite accordingly to https://github.com/adobe/aio-cli-plugin-app-storage/pull/36/changes#r2869855342