토큰 전달 위치 파악

우선 소켓에 토큰을 어떻게 담을지 생각해야했다. headers에 전달하는것이 아니기 때문에 마땅한 위치를 결정해야했다.

Untitled

websocket 라이브러리에서 제공하는 @ConnectedSocket 데코레이터를 통해 sokcet 객체를 받을 수 있는데 이 Socket은

Untitled

읽기가능한 속성 4가지를 포함하고 있다.

이 중 익숙한 handshake의 인터페이스를 보면

export interface Handshake {
    /**
     * The headers sent as part of the handshake
     */
    headers: IncomingHttpHeaders;
    /**
     * The date of creation (as string)
     */
    time: string;
    /**
     * The ip of the client
     */
    address: string;
    /**
     * Whether the connection is cross-domain
     */
    xdomain: boolean;
    /**
     * Whether the connection is secure
     */
    secure: boolean;
    /**
     * The date of creation (as unix timestamp)
     */
    issued: number;
    /**
     * The request URL string
     */
    url: string;
    /**
     * The query object
     */
    query: ParsedUrlQuery;
    /**
     * The auth object
     */
    auth: {
        [key: string]: any;
    };
}

다양한 인터페이스 구성 요소들을 확인 할 수 있다.

Untitled

여기서 headers의 설명을 보면

핸드셰이크의 일부로 전송되는 헤더라고 친절하게 설명해주고있다.

그렇기 때문에 헤더가아닌 다른곳에 할당해야한다.

마침 라이브러리 자체에서 auth라는 키를 통해 토큰의 위치를 제공해 주고있었다.