-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Basic Auth provider for all clients fixes #165
- Loading branch information
Showing
7 changed files
with
168 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
import debug from 'debug' | ||
|
||
import { NullAuthProvider, OAuthProvider } from '../oauth' | ||
import { BasicAuthProvider } from '../oauth/lib/BasicAuthProvider' | ||
|
||
import { CamundaPlatform8Configuration } from './Configuration' | ||
|
||
const trace = debug('camunda:oauth') | ||
|
||
export function constructOAuthProvider(config: CamundaPlatform8Configuration) { | ||
if (config.CAMUNDA_OAUTH_DISABLED) { | ||
trace(`Auth strategy is ${config.CAMUNDA_AUTH_STRATEGY}`) | ||
trace(`OAuth disabled is ${config.CAMUNDA_OAUTH_DISABLED}`) | ||
if ( | ||
config.CAMUNDA_OAUTH_DISABLED || | ||
config.CAMUNDA_AUTH_STRATEGY === 'NONE' | ||
) { | ||
trace(`Disabling Auth`) | ||
return new NullAuthProvider() | ||
} else { | ||
return new OAuthProvider({ config }) | ||
if (config.CAMUNDA_AUTH_STRATEGY === 'BASIC') { | ||
trace(`Using Basic Auth`) | ||
return new BasicAuthProvider({ config }) | ||
} else { | ||
trace(`Using OAuth`) | ||
return new OAuthProvider({ config }) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import debug from 'debug' | ||
|
||
import { | ||
CamundaEnvironmentConfigurator, | ||
CamundaPlatform8Configuration, | ||
DeepPartial, | ||
RequireConfiguration, | ||
} from '../../lib' | ||
|
||
import { IOAuthProvider, TokenGrantAudienceType } from './IOAuthProvider' | ||
|
||
const trace = debug('camunda:oauth') | ||
|
||
export class BasicAuthProvider implements IOAuthProvider { | ||
private username: string | undefined | ||
private password: string | undefined | ||
constructor(options?: { | ||
config?: DeepPartial<CamundaPlatform8Configuration> | ||
}) { | ||
const config = CamundaEnvironmentConfigurator.mergeConfigWithEnvironment( | ||
options?.config ?? {} | ||
) | ||
this.username = RequireConfiguration( | ||
config.CAMUNDA_BASIC_AUTH_USERNAME, | ||
'CAMUNDA_BASIC_AUTH_USERNAME' | ||
) | ||
this.password = RequireConfiguration( | ||
config.CAMUNDA_BASIC_AUTH_PASSWORD, | ||
'CAMUNDA_BASIC_AUTH_PASSWORD' | ||
) | ||
} | ||
getToken(audience: TokenGrantAudienceType): Promise<string> { | ||
trace(`Requesting token for audience ${audience}`) | ||
const token = Buffer.from(`${this.username}:${this.password}`).toString( | ||
'base64' | ||
) | ||
return Promise.resolve(token) | ||
} | ||
} |