-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make iam assume authenticator immutable
Signed-off-by: Dustin Popp <dustinpopp@ibm.com>
- Loading branch information
Showing
16 changed files
with
384 additions
and
190 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
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
86 changes: 86 additions & 0 deletions
86
auth/authenticators/iam-request-based-authenticator-immutable.ts
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,86 @@ | ||
/** | ||
* (C) Copyright IBM Corp. 2024. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { IamRequestBasedTokenManager } from '../token-managers/iam-request-based-token-manager'; | ||
import { | ||
BaseOptions, | ||
TokenRequestBasedAuthenticatorImmutable, | ||
} from './token-request-based-authenticator-immutable'; | ||
|
||
/** Configuration options for IAM Request based authentication. */ | ||
export interface IamRequestOptions extends BaseOptions { | ||
/** | ||
* The `clientId` and `clientSecret` fields are used to form a "basic" | ||
* authorization header for IAM token requests. | ||
*/ | ||
clientId?: string; | ||
/** | ||
* The `clientId` and `clientSecret` fields are used to form a "basic" | ||
* authorization header for IAM token requests. | ||
*/ | ||
clientSecret?: string; | ||
|
||
/** | ||
* The "scope" parameter to use when fetching the bearer token from the IAM token server. | ||
*/ | ||
scope?: string; | ||
} | ||
|
||
/** | ||
* The IamRequestBasedAuthenticatorImmutable provides shared configuration and functionality | ||
* for authenticators that interact with the IAM token service. This authenticator | ||
* is not meant for use on its own. | ||
*/ | ||
export class IamRequestBasedAuthenticatorImmutable extends TokenRequestBasedAuthenticatorImmutable { | ||
protected tokenManager: IamRequestBasedTokenManager; | ||
|
||
protected clientId: string; | ||
|
||
protected clientSecret: string; | ||
|
||
protected scope: string; | ||
|
||
/** | ||
* | ||
* Create a new IamRequestBasedAuthenticatorImmutable instance. | ||
* | ||
* @param options - Configuration options for IAM authentication. | ||
* This should be an object containing these fields: | ||
* - url: (optional) the endpoint URL for the token service | ||
* - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate | ||
* should be disabled or not | ||
* - headers: (optional) a set of HTTP headers to be sent with each request to the token service | ||
* - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic | ||
* Authorization header to be included in each request to the token service | ||
* - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic | ||
* Authorization header to be included in each request to the token service | ||
* - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service | ||
* | ||
* @throws Error: the configuration options are not valid. | ||
*/ | ||
constructor(options: IamRequestOptions) { | ||
// all parameters are optional | ||
options = options || ({} as IamRequestOptions); | ||
|
||
super(options); | ||
|
||
this.clientId = options.clientId; | ||
this.clientSecret = options.clientSecret; | ||
this.scope = options.scope; | ||
|
||
this.tokenManager = new IamRequestBasedTokenManager(options); | ||
} | ||
} |
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
Oops, something went wrong.