Skip to content

Commit 06230c3

Browse files
authored
fix: Reintroduce option to pass iss in getClientCredentials function (#5502)
1 parent 3a7fae0 commit 06230c3

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

.changeset/nice-comics-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sap-cloud-sdk/connectivity': patch
3+
---
4+
5+
[Fixed Issue] Reintroduce option to pass `iss` property to `getClientCredentialsToken` function.

packages/connectivity/src/scp-cf/jwt/jwt.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,26 @@ export function getTenantId(
6262
return decodedJwt.zid || decodedJwt.app_tid || undefined;
6363
}
6464

65+
/**
66+
* Check if the given JWT is not an IAS token.
67+
* Currently, there are only two domains for IAS tokens:
68+
* `accounts.ondemand.com` and `accounts400.onemand.com`.
69+
* @param decodedJwt - The decoded JWT to check.
70+
* @returns Whether the given JWT is not an IAS token.
71+
*/
72+
function isNotIasToken(decodedJwt: JwtPayload): boolean {
73+
return (
74+
!decodedJwt.iss?.includes('accounts.ondemand.com') &&
75+
!decodedJwt.iss?.includes('accounts400.ondemand.com')
76+
);
77+
}
78+
6579
/**
6680
* @internal
67-
* Retrieve the subdomain from the decoded XSUAA JWT. If the JWT is not in XSUAA format, returns `undefined`.
68-
* @param jwt - JWT to retrieve the subdomain from.
81+
* Retrieve the subdomain from the decoded XSUAA JWT or ISS object.
82+
* If it is an IAS JWT, or the passed object doesn't contain an ISS propety,
83+
* returns `undefined`.
84+
* @param jwt - JWT or ISS object to retrieve the subdomain from.
6985
* @returns The subdomain, if available.
7086
*/
7187
export function getSubdomain(
@@ -74,7 +90,7 @@ export function getSubdomain(
7490
const decodedJwt = jwt ? decodeJwt(jwt) : {};
7591
return (
7692
decodedJwt?.ext_attr?.zdn ||
77-
(isXsuaaToken(decodedJwt) ? getIssuerSubdomain(decodedJwt) : undefined)
93+
(isNotIasToken(decodedJwt) ? getIssuerSubdomain(decodedJwt) : undefined)
7894
);
7995
}
8096

0 commit comments

Comments
 (0)