Skip to content

feat: implement OAuth2 authentication for EAM API access - #1646

Open
yoganandaness wants to merge 2 commits into
developfrom
chore/eam-camel-oauth2
Open

feat: implement OAuth2 authentication for EAM API access#1646
yoganandaness wants to merge 2 commits into
developfrom
chore/eam-camel-oauth2

Conversation

@yoganandaness

Copy link
Copy Markdown
Contributor

Description

Migrates the EAM asset registration integration from calling EAM directly to
calling it through the Camel API, and switches authentication from Basic Auth
to an OAuth2 client_credentials flow.

  • Added getAccessToken util that requests an OAuth2 access token from the
    configured token endpoint (client_credentials grant, Basic base64(clientId:clientSecret)
    auth, url-encoded grant_type/scope/aud body).
  • performApiRequest now obtains an access token and sends it as a Bearer
    token to the Camel endpoints; the old Basic auth and tenant/organization
    headers were removed.
  • Reworked the EAM env vars: removed EAM_AUTH_USER, EAM_AUTH_PASSWORD,
    EAM_AUTH_TENANT; added EAM_OAUTH_TOKEN_URL, EAM_AUTH_CLIENT_ID,
    EAM_AUTH_CLIENT_SECRET, EAM_OAUTH_SCOPE, EAM_OAUTH_AUDIENCE.
    EAM_API_URL now points at the Camel base URL (the /assets and
    /casemanagement paths are appended as before).
  • Updated example.development.env, CI workflow env, and configuration docs.

Motivation and Context

The IT team has decided that UO should no longer call EAM directly but go
through the Camel API, and the underlying OAuth has changed accordingly. This
change adapts our integration to the new auth flow (OAuth2 token exchange +
Bearer token) and the new Camel endpoints.

How Has This Been Tested

  • Unit tests for the new getAccessToken util (token request shape, error
    handling) pass.
  • Existing request-payload unit tests remain green (payload shape is unchanged).
  • Pending: end-to-end verification against the Camel test environment once the
    client secret is available, to confirm the Camel response body matches the
    currently-parsed shape.

Fixes

Changes

  • Non-breaking for the request payloads; breaking for deployment config
    (new/removed environment variables must be set in each environment).
  • Backend only (apps/backend/src/services/assetRegistrar/eam/), CI workflow,
    and documentation.

Depends on

Tests included/Docs Updated?

  • I have added tests to cover my changes.
  • All relevant doc has been updated

@yoganandaness
yoganandaness requested a review from a team as a code owner July 15, 2026 12:37
@yoganandaness
yoganandaness requested review from Bhaswati1148, TCMeldrum, jekabs-karklins and zacharyjhankin and removed request for a team and Bhaswati1148 July 15, 2026 12:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the backend EAM asset registration integration to call the Camel API and authenticate via an OAuth2 client_credentials token exchange, replacing the previous Basic-auth approach. This aligns the service with the new IT-mandated integration path and auth mechanism.

Changes:

  • Added getAccessToken utility for OAuth2 token retrieval (client credentials + Basic client auth + form-encoded body).
  • Updated performApiRequest to send Authorization: Bearer <token> to Camel endpoints and removed the old Basic-auth headers.
  • Updated environment variable documentation, example .env, and CI workflow configuration for the new OAuth2/Camel settings.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
documentation/docs/developer-guide/configuration.md Documents the updated EAM/Camel OAuth2 environment variables.
apps/backend/src/services/assetRegistrar/eam/utils/performApiRequest.ts Switches API calls to Bearer token auth via getAccessToken.
apps/backend/src/services/assetRegistrar/eam/utils/getEnvOrThrow.ts Updates the allowed EAM env var keys to include OAuth2 settings.
apps/backend/src/services/assetRegistrar/eam/utils/getAccessToken.ts Implements OAuth2 client-credentials token exchange for EAM/Camel access.
apps/backend/src/services/assetRegistrar/eam/utils/getAccessToken.spec.ts Adds unit tests validating token request shape and error handling.
apps/backend/example.development.env Updates the example backend env file to the new OAuth2 variable set.
.github/workflows/test-build.yml Updates CI env vars for the EAM integration to the new OAuth2 variable set.

Comment on lines 10 to 12
try {
const base64Credentials = Buffer.from(
`${getEnvOrThrow('EAM_AUTH_USER')}:${getEnvOrThrow('EAM_AUTH_PASSWORD')}`
).toString('base64');
const accessToken = await getAccessToken();

Comment on lines +23 to +27
describe('getAccessToken', () => {
afterEach(() => {
jest.restoreAllMocks();
});

Comment on lines +533 to 536
EAM_OAUTH_SCOPE: uos.api.read
EAM_OAUTH_AUDIENCE: https://ios.esss.lu.se/
EAM_AUTH_ORGANIZATION: dummyOrg
EAM_EQUIPMENT_PART_CODE: 12413
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants