Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conversation auth token update propagates to translation service connection #722

Merged
merged 8 commits into from
Aug 23, 2023
Merged
2 changes: 1 addition & 1 deletion src/common.speech/CognitiveTokenAuthentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AuthInfo, IAuthentication } from "./IAuthentication";
import { HeaderNames } from "./HeaderNames";

export class CognitiveTokenAuthentication implements IAuthentication {
private static privTokenPrefix: string = "bearer ";
private static privTokenPrefix: string = "Bearer ";
private privFetchCallback: (authFetchEventId: string) => Promise<string>;
private privFetchOnExpiryCallback: (authFetchEventId: string) => Promise<string>;

Expand Down
2 changes: 1 addition & 1 deletion src/common.speech/ServiceRecognizerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export abstract class ServiceRecognizerBase implements IDisposable {
}

public set authentication(auth: IAuthentication) {
this.privAuthentication = this.authentication;
this.privAuthentication = auth;
}

public isDisposed(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ export class ConversationServiceAdapter extends ServiceRecognizerBase {
return Promise.resolve(authorizationToken);
});
this.authentication = token;
this.privConversationServiceConnector.onToken(token);

break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class ConversationTranslatorConnectionFactory extends ConnectionFactoryBa

headers[HeaderNames.ConnectionId] = connectionId;
headers[RestConfigBase.configParams.token] = convInfo.token;
if (authInfo.token) {
if (!!authInfo.token) {
headers[authInfo.headerName] = authInfo.token;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import {
BackgroundEvent,
Events,
Timeout
Timeout,
} from "../../common/Exports";
import { AudioConfigImpl } from "../../sdk/Audio/AudioConfig";
import { Contracts } from "../../sdk/Contracts";
Expand Down Expand Up @@ -207,6 +207,13 @@ export class ConversationTranslatorRecognizer extends Recognizer implements Conv
}
}

/**
* Handle update of service auth token (#694)
*/
public onToken(token: IAuthentication): void {
this.privConversation.onToken(token);
}

/**
* Close and dispose the recognizer
*/
Expand Down
4 changes: 4 additions & 0 deletions src/sdk/Transcription/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ConversationRecognizerFactory,
ConversationTranslatorCommandTypes,
ConversationTranslatorMessageTypes,
IAuthentication,
IInternalConversation,
IInternalParticipant,
InternalParticipants,
Expand Down Expand Up @@ -323,6 +324,9 @@ export class ConversationImpl extends Conversation implements IDisposable {
this.privConversationTranslator = conversationTranslator;
}

public onToken(token: IAuthentication): void {
this.privConversationTranslator.onToken(token);
}

/**
* Create a new conversation as Host
Expand Down
10 changes: 10 additions & 0 deletions src/sdk/Transcription/ConversationTranslator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import {
ConversationConnectionConfig,
IAuthentication,
ServicePropertiesPropertyName,
} from "../../common.speech/Exports";
import { ConversationTranslatorConnectionFactory } from "../../common.speech/Transcription/ConversationTranslatorConnectionFactory";
Expand Down Expand Up @@ -108,6 +109,11 @@ class ConversationTranslationRecognizer extends TranslationRecognizer {
this.privSpeechState = newState;
}

public set authentication(token: IAuthentication) {
this.privReco.authentication = token;
}


public onConnection(): void {
this.privSpeechState = SpeechState.Connected;
}
Expand Down Expand Up @@ -219,6 +225,10 @@ export class ConversationTranslator extends ConversationCommon implements IConve
return true;
}

public onToken(token: IAuthentication): void {
this.privCTRecognizer.authentication = token;
}

public setServiceProperty(name: string, value: string): void {
const currentProperties: IStringDictionary<string> = JSON.parse(this.privProperties.getProperty(ServicePropertiesPropertyName, "{}")) as IStringDictionary<string>;

Expand Down