my authorizer: ```import { APIGatewayRequestAu...
# ory-network
c
my authorizer:
Copy code
import {
    APIGatewayRequestAuthorizerEventV2,
    APIGatewayRequestSimpleAuthorizerHandlerV2, APIGatewaySimpleAuthorizerResult,
    APIGatewaySimpleAuthorizerWithContextResult
} from "aws-lambda";
import {Configuration, Session, FrontendApi} from "@ory/client";

export const handler: APIGatewayRequestSimpleAuthorizerHandlerV2 = async (event: APIGatewayRequestAuthorizerEventV2): Promise<APIGatewaySimpleAuthorizerResult | APIGatewaySimpleAuthorizerWithContextResult<Session | Object>> => {
    const basePath = process.env.ORY_URL;
    const ory = new FrontendApi(
        new Configuration({
            basePath,
            baseOptions: {
                withCredentials: true,
            },
        }),
    );

    try {
        if (event.headers?.cookie) {
            const orySession = await ory.toSession({
                cookie: event.headers?.cookie,
            });
            return {
                isAuthorized: true,
                context: orySession.data
            };
        } else if (event.headers?.['x-session-token']) {
            const orySession = await ory.toSession({
                xSessionToken: event.headers?.['x-session-token']
            });
            return {
                isAuthorized: true,
                context: orySession.data
            };
        }
        return {
            isAuthorized: false,
        };
    } catch (e) {
        return {
            isAuthorized: false,
        };
    }
}
1
🙌 1