Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
Support temporary credentials
Browse files Browse the repository at this point in the history
When using temporary credentials (like AWS roles) we need to pass in an
extra parameter (session token) to the signing function to create a
valid signature.
  • Loading branch information
igoratron committed Apr 17, 2020
1 parent b7b83a1 commit fe87b61
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/AwsTranscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import { StreamingClient } from "./StreamingClient"
export class AwsTranscribe {
private accessKeyId!: string
private secretAccessKey!: string
private sessionToken: string | undefined

constructor(config?: ClientConfig) {
// get from environment if config not provided
this.setAccessKeyId(config?.accessKeyId || process.env.AWS_ACCESS_KEY_ID)
this.setSecretAccessKey(config?.secretAccessKey || process.env.AWS_SECRET_ACCESS_KEY)
this.setSessionToken(config?.sessionToken || process.env.AWS_SESSION_TOKEN)
}

private createPreSignedUrl(config: TranscribeStreamConfig) {
Expand All @@ -27,6 +29,7 @@ export class AwsTranscribe {
{
key: this.accessKeyId,
secret: this.secretAccessKey,
sessionToken: this.sessionToken,
protocol: "wss",
expires: 15,
region: region,
Expand All @@ -51,4 +54,8 @@ export class AwsTranscribe {
this.secretAccessKey = secretAccessKey
}
}

setSessionToken(sessionToken: string | undefined) {
this.sessionToken = sessionToken
}
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type LANGUAGES = "en-US" | "en-AU" | "en-GB" | "fr-CA" | "fr-FR" | "es-US
export interface ClientConfig {
accessKeyId?: string
secretAccessKey?: string
sessionToken?: string
}

export interface TranscribeStreamConfig {
Expand Down

0 comments on commit fe87b61

Please sign in to comment.