@@ -5,36 +5,24 @@ import {
5
5
RequestBodyTypes ,
6
6
} from '@dynatrace-sdk/http-client' ;
7
7
import { 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' ;
22
10
23
11
/**
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
25
13
* @param clientId - OAuth Client ID for Dynatrace
26
14
* @param clientSecret - Oauth Client Secret for Dynatrace
27
- * @param authUrl - SSO Authentication URL
15
+ * @param ssoAuthUrl - SSO Authentication URL
28
16
* @param scopes - List of requested scopes
29
17
* @returns
30
18
*/
31
19
const requestToken = async (
32
20
clientId : string ,
33
21
clientSecret : string ,
34
- authUrl : string ,
22
+ ssoAuthUrl : string ,
35
23
scopes : string [ ] ,
36
24
) : Promise < OAuthTokenResponse > => {
37
- const res = await fetch ( authUrl , {
25
+ const res = await fetch ( ssoAuthUrl , {
38
26
method : 'POST' ,
39
27
headers : {
40
28
'Content-Type' : 'application/x-www-form-urlencoded' ,
@@ -83,7 +71,9 @@ export class ExtendedOauthClient extends _OAuthHttpClient {
83
71
}
84
72
}
85
73
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
+ */
87
77
export const createOAuthClient = async (
88
78
clientId : string ,
89
79
clientSecret : string ,
@@ -130,28 +120,3 @@ export const createOAuthClient = async (
130
120
userAgent ,
131
121
) ;
132
122
} ;
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