@@ -5,36 +5,24 @@ import {
55 RequestBodyTypes ,
66} from '@dynatrace-sdk/http-client' ;
77import { getSSOUrl } from 'dt-app' ;
8- import { version as VERSION } from '../package.json' ;
9-
10- // Define the OAuthTokenResponse interface to match the expected structure of the response
11- export interface OAuthTokenResponse {
12- scope ?: string ;
13- token_type ?: string ;
14- expires_in ?: number ;
15- access_token ?: string ;
16- errorCode ?: number ;
17- message ?: string ;
18- issueId ?: string ;
19- error ?: string ;
20- error_description ?: string ;
21- }
8+ import { version as VERSION } from '../../package.json' ;
9+ import { OAuthTokenResponse } from './types' ;
2210
2311/**
24- * Uses the provided oauth Client ID and Secret and requests a token
12+ * Uses the provided oauth Client ID and Secret and requests a token via client-credentials flow
2513 * @param clientId - OAuth Client ID for Dynatrace
2614 * @param clientSecret - Oauth Client Secret for Dynatrace
27- * @param authUrl - SSO Authentication URL
15+ * @param ssoAuthUrl - SSO Authentication URL
2816 * @param scopes - List of requested scopes
2917 * @returns
3018 */
3119const requestToken = async (
3220 clientId : string ,
3321 clientSecret : string ,
34- authUrl : string ,
22+ ssoAuthUrl : string ,
3523 scopes : string [ ] ,
3624) : Promise < OAuthTokenResponse > => {
37- const res = await fetch ( authUrl , {
25+ const res = await fetch ( ssoAuthUrl , {
3826 method : 'POST' ,
3927 headers : {
4028 'Content-Type' : 'application/x-www-form-urlencoded' ,
@@ -83,7 +71,9 @@ export class ExtendedOauthClient extends _OAuthHttpClient {
8371 }
8472}
8573
86- /** Create an Oauth Client based on clientId, clientSecret, environmentUrl and scopes */
74+ /** Create an Oauth Client based on clientId, clientSecret, environmentUrl and scopes
75+ * This uses a client-credentials flow to request a token from the SSO endpoint.
76+ */
8777export const createOAuthClient = async (
8878 clientId : string ,
8979 clientSecret : string ,
@@ -130,28 +120,3 @@ export const createOAuthClient = async (
130120 userAgent ,
131121 ) ;
132122} ;
133-
134- /** Helper function to call an app-function via platform-api */
135- export const callAppFunction = async (
136- dtClient : _OAuthHttpClient ,
137- appId : string ,
138- functionName : string ,
139- payload : any ,
140- ) => {
141- console . error ( `Sending payload ${ JSON . stringify ( payload ) } ` ) ;
142-
143- const response = await dtClient . send ( {
144- url : `/platform/app-engine/app-functions/v1/apps/${ appId } /api/${ functionName } ` ,
145- method : 'POST' ,
146- headers : {
147- 'Accept' : 'application/json' ,
148- 'Content-Type' : 'application/json' ,
149- } ,
150- body : payload ,
151- statusValidator : ( status : number ) => {
152- return [ 200 ] . includes ( status ) ;
153- } ,
154- } ) ;
155-
156- return await response . body ( 'json' ) ;
157- } ;
0 commit comments