Skip to content

Commit

Permalink
Merge pull request #373 from camunda/alpha
Browse files Browse the repository at this point in the history
Alpha
  • Loading branch information
jwulf authored Feb 5, 2025
2 parents 3745010 + b50d41d commit 787e439
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/__tests__/oauth/OAuthProvider.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,11 @@ describe('OAuthProvider', () => {
CAMUNDA_BASIC_AUTH_USERNAME: 'admin',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any)
const token = await oAuthProvider.getToken('ZEEBE')
const Authorization = await oAuthProvider.getToken('ZEEBE')
await got
.get('http://localhost:3033', {
headers: {
Authorization: 'Basic ' + token,
Authorization,
},
})
.then((res) => {
Expand Down Expand Up @@ -634,11 +634,11 @@ describe('OAuthProvider', () => {
CAMUNDA_OAUTH_TOKEN: 'mysecrettoken',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any)
const token = await oAuthProvider.getToken('ZEEBE')
const Authorization = await oAuthProvider.getToken('ZEEBE')
await got
.get('http://localhost:3033', {
headers: {
Authorization: 'Bearer ' + token,
Authorization,
},
})
.then((res) => {
Expand Down
2 changes: 1 addition & 1 deletion src/admin/lib/AdminApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class AdminApiClient {
const token = await this.oAuthProvider.getToken('CONSOLE')
const headers = {
'content-type': 'application/json',
authorization: `Bearer ${token}`,
authorization: token,
'user-agent': this.userAgentString,
accept: '*/*',
}
Expand Down
2 changes: 1 addition & 1 deletion src/c8/lib/CamundaRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class CamundaRestClient {

const headers = {
'content-type': 'application/json',
authorization: `Bearer ${token}`,
authorization: token,
'user-agent': this.userAgentString,
accept: '*/*',
}
Expand Down
3 changes: 1 addition & 2 deletions src/modeler/lib/ModelerAPIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ export class ModelerApiClient {
}

private async getHeaders() {
const token = await this.oAuthProvider.getToken('MODELER')
const authorization = `Bearer ${token}`
const authorization = await this.oAuthProvider.getToken('MODELER')
const headers = {
'content-type': 'application/json',
authorization,
Expand Down
2 changes: 1 addition & 1 deletion src/oauth/lib/BasicAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ export class BasicAuthProvider implements IOAuthProvider {
const token = Buffer.from(`${this.username}:${this.password}`).toString(
'base64'
)
return Promise.resolve(token)
return Promise.resolve(`Basic ${token}`)
}
}
2 changes: 1 addition & 1 deletion src/oauth/lib/BearerAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ export class BearerAuthProvider implements IOAuthProvider {
public async getToken(audienceType: TokenGrantAudienceType): Promise<string> {
debug(`Token request for ${audienceType}`)

return Promise.resolve(this.bearerToken)
return Promise.resolve(`Bearer ${this.bearerToken}`)
}
}
10 changes: 7 additions & 3 deletions src/oauth/lib/OAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class OAuthProvider implements IOAuthProvider {
trace(`In-memory token ${token.audience} is expired`)
} else {
trace(`Using in-memory cached token ${token.audience}`)
return this.tokenCache[key].access_token
return this.addBearer(this.tokenCache[key].access_token)
}
}
if (this.useFileCache) {
Expand All @@ -203,7 +203,7 @@ export class OAuthProvider implements IOAuthProvider {
trace(`File cached token ${cachedToken.audience} is expired`)
} else {
trace(`Using file cached token ${cachedToken.audience}`)
return cachedToken.access_token
return this.addBearer(cachedToken.access_token)
}
}
}
Expand Down Expand Up @@ -344,7 +344,7 @@ export class OAuthProvider implements IOAuthProvider {
})
}
this.sendToMemoryCache({ audience: audienceType, token })
return token.access_token
return this.addBearer(token.access_token)
})
)
}
Expand Down Expand Up @@ -475,4 +475,8 @@ export class OAuthProvider implements IOAuthProvider {
private getAudience(audience: TokenGrantAudienceType) {
return this.audienceMap[audience]
}

private addBearer(token: string) {
return `Bearer ${token}`
}
}
4 changes: 2 additions & 2 deletions src/operate/lib/OperateApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ export class OperateApiClient {
}

private async getHeaders() {
const token = await this.oAuthProvider.getToken('OPERATE')
const authorization = await this.oAuthProvider.getToken('OPERATE')

return {
'content-type': 'application/json',
authorization: `Bearer ${token}`,
authorization,
'user-agent': this.userAgentString,
accept: '*/*',
}
Expand Down
4 changes: 2 additions & 2 deletions src/optimize/lib/OptimizeApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ export class OptimizeApiClient {
}

private async getHeaders(auth = true) {
const token = await this.oAuthProvider.getToken('OPTIMIZE')
const authorization = await this.oAuthProvider.getToken('OPTIMIZE')

const authHeader: { authorization: string } | Record<string, never> = auth
? {
authorization: `Bearer ${token}`,
authorization,
}
: {}

Expand Down
4 changes: 2 additions & 2 deletions src/tasklist/lib/TasklistApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ export class TasklistApiClient {
}

private async getHeaders() {
const token = await this.oAuthProvider.getToken('TASKLIST')
const authorization = await this.oAuthProvider.getToken('TASKLIST')
return {
'content-type': 'application/json',
authorization: `Bearer ${token}`,
authorization,
'user-agent': this.userAgentString,
accept: '*/*',
}
Expand Down
4 changes: 2 additions & 2 deletions src/zeebe/lib/GrpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ export class GrpcClient extends EventEmitter {
const metadata = new Metadata({ waitForReady: false })
metadata.add('user-agent', this.userAgentString)
if (this.oAuth) {
const token = await this.oAuth.getToken('ZEEBE')
metadata.add('Authorization', `Bearer ${token}`)
const authorization = await this.oAuth.getToken('ZEEBE')
metadata.add('Authorization', authorization)
}
return metadata
}
Expand Down
4 changes: 2 additions & 2 deletions src/zeebe/zb/ZeebeRESTClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ export class ZeebeRestClient {
}

private async getHeaders() {
const token = await this.oAuthProvider.getToken('ZEEBE')
const authorization = await this.oAuthProvider.getToken('ZEEBE')

const headers = {
'content-type': 'application/json',
authorization: `Bearer ${token}`,
authorization,
'user-agent': this.userAgentString,
accept: '*/*',
}
Expand Down

0 comments on commit 787e439

Please sign in to comment.