3

TypeScript servicestack-clientを使用して、ServiceStack ServerからSSEイベントにフックしようとしています。Typescript Servicestack SSEイベントのクライアント認証

認証がAuthenticateクラスを送信し、sesssionクッキーを受信することにより構成されています

import { ServerEventsClient } from 'servicestack-client'; 

export class ServicestackService { 
    private sseClient: ServerEventsClient; 

    constructor() { 
     this.createSseClient(); 
    } 

    login(username: string, password: string) { 
     let request = new Authenticate(username, password); 
     return this.sseClient.serviceClient.post(request); 
    } 

    startClient() { 
     this.sseClient.start(); 
     console.log('eventSource created'); 
    } 

    subscribeChannel(channel: string) { 
     this.sseClient.subscribeToChannels(channel); 
    } 

    private createSseClient() { 
     this.sseClient = new ServerEventsClient('http://ss_api_url', ['*'], { 
     handlers: { ...define handlers for onConnect & onMessage here... } 
     } 
    } 

}  

上記のコードが正常にagainsのservicestackのAPIおよびセキュアなAPIリクエストを認証に適しています。 startClient()メソッドは、すべてのログイン認証が完了した後に呼び出され、オブジェクトをプロパティとしてthis.sseClientに作成します。

しかし、このオブジェクトはwithCredentials: falseです! したがって、servicestackクライアントがCookiesヘッダーを送信していないため、次のチャネルサブスクリプションのいずれも認証されないため失敗します。

認証済みSSE接続はどのようにして実現できますか?

答えて

1

私はちょうどあなたがservicestack-clientの最新v0.0.34にアップグレードした場合ので、それは自動的に有効になりますtrueにどのデフォルトthis commitwithCredentialsのEventSourceオプションを指定するためのサポートを追加しました。

var sseClient = new ServerEventsClient('http://ss_api_url', ['*'], { ... }); 

sseClient.withCredentials = false; 
:必要に応じて

、それを無効にすることができます

関連する問題