-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1728c0c
commit f6a4901
Showing
6 changed files
with
147 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import CredentialProvider from "./CredentialProvider"; | ||
import TokenManager from "../http/bearer_token/TokenManager"; | ||
import AuthStrategy from "../auth_strategy/AuthStrategy"; | ||
import ApiTokenManager from "../http/bearer_token/ApiTokenManager"; | ||
import TokenAuthStrategy from "../auth_strategy/TokenAuthStrategy"; | ||
|
||
class ClientCredentialProvider extends CredentialProvider { | ||
grantType: string; | ||
clientId: string; | ||
clientSecret: string; | ||
tokenManager: TokenManager | null; | ||
|
||
constructor() { | ||
super("client-credentials"); | ||
this.grantType = "client_credentials"; | ||
this.clientId = ""; | ||
this.clientSecret = ""; | ||
this.tokenManager = null; | ||
} | ||
|
||
public toAuthStrategy(): AuthStrategy { | ||
if (this.tokenManager == null) { | ||
this.tokenManager = new ApiTokenManager({ | ||
grantType: this.grantType, | ||
clientId: this.clientId, | ||
clientSecret: this.clientSecret, | ||
}); | ||
} | ||
return new TokenAuthStrategy(this.tokenManager); | ||
} | ||
} | ||
|
||
namespace ClientCredentialProvider { | ||
export class ClientCredentialProviderBuilder { | ||
private readonly instance: ClientCredentialProvider; | ||
|
||
constructor() { | ||
this.instance = new ClientCredentialProvider(); | ||
} | ||
|
||
public setClientId(clientId: string): ClientCredentialProviderBuilder { | ||
this.instance.clientId = clientId; | ||
return this; | ||
} | ||
|
||
public setClientSecret(clientSecret: string): ClientCredentialProviderBuilder { | ||
this.instance.clientSecret = clientSecret; | ||
return this; | ||
} | ||
|
||
public setTokenManager(tokenManager: TokenManager): ClientCredentialProviderBuilder { | ||
this.instance.tokenManager = tokenManager; | ||
return this; | ||
} | ||
|
||
public build(): ClientCredentialProvider { | ||
return this.instance; | ||
} | ||
} | ||
} | ||
|
||
export = ClientCredentialProvider; | ||
|
||
|
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,9 @@ | ||
import AuthStrategy from "../auth_strategy/AuthStrategy"; | ||
|
||
export default abstract class CredentialProvider { | ||
private authType: string; | ||
protected constructor(authType: string) { | ||
this.authType = authType; | ||
} | ||
abstract toAuthStrategy(): AuthStrategy; | ||
} |
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,13 @@ | ||
import CredentialProvider from "./CredentialProvider"; | ||
import AuthStrategy from "../auth_strategy/AuthStrategy"; | ||
import NoAuthStrategy from "../auth_strategy/NoAuthStrategy"; | ||
|
||
export default class NoAuthCredentialProvider extends CredentialProvider { | ||
constructor() { | ||
super("client-credentials"); | ||
} | ||
|
||
public toAuthStrategy(): AuthStrategy { | ||
return new NoAuthStrategy(); | ||
} | ||
} |
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
src/base/BaseTwilio.ts