@logto/remix 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/framework/get-cookie-header-from-request.cjs +5 -0
- package/lib/framework/get-cookie-header-from-request.d.ts +1 -0
- package/lib/framework/get-cookie-header-from-request.js +3 -0
- package/lib/framework/mocks.d.ts +22 -0
- package/lib/index.cjs +24 -0
- package/lib/index.d.ts +3 -7
- package/lib/index.js +17 -482
- package/lib/infrastructure/logto/create-client.cjs +17 -0
- package/lib/infrastructure/logto/create-client.d.ts +6 -0
- package/lib/infrastructure/logto/create-client.js +11 -0
- package/lib/infrastructure/logto/create-client.spec.d.ts +1 -0
- package/lib/infrastructure/logto/create-storage.cjs +30 -0
- package/lib/infrastructure/logto/create-storage.d.ts +14 -0
- package/lib/infrastructure/logto/create-storage.js +28 -0
- package/lib/infrastructure/logto/create-storage.spec.d.ts +1 -0
- package/lib/infrastructure/logto/get-context.cjs +12 -0
- package/lib/infrastructure/logto/get-context.d.ts +11 -0
- package/lib/infrastructure/logto/get-context.js +10 -0
- package/lib/infrastructure/logto/handle-sign-in-callback.cjs +12 -0
- package/lib/infrastructure/logto/handle-sign-in-callback.d.ts +14 -0
- package/lib/infrastructure/logto/handle-sign-in-callback.js +10 -0
- package/lib/infrastructure/logto/handle-sign-in.cjs +30 -0
- package/lib/infrastructure/logto/handle-sign-in.d.ts +15 -0
- package/lib/infrastructure/logto/handle-sign-in.js +28 -0
- package/lib/infrastructure/logto/handle-sign-out.cjs +26 -0
- package/lib/infrastructure/logto/handle-sign-out.d.ts +11 -0
- package/lib/infrastructure/logto/handle-sign-out.js +24 -0
- package/lib/infrastructure/logto/index.cjs +21 -0
- package/lib/infrastructure/logto/index.d.ts +26 -0
- package/lib/infrastructure/logto/index.js +19 -0
- package/lib/useCases/getContext/GetContextController.cjs +21 -0
- package/lib/useCases/getContext/GetContextController.d.ts +13 -0
- package/lib/useCases/getContext/GetContextController.js +19 -0
- package/lib/useCases/getContext/GetContextController.spec.d.ts +1 -0
- package/lib/useCases/getContext/GetContextUseCase.cjs +13 -0
- package/lib/useCases/getContext/GetContextUseCase.d.ts +15 -0
- package/lib/useCases/getContext/GetContextUseCase.js +11 -0
- package/lib/useCases/getContext/GetContextUseCase.spec.d.ts +1 -0
- package/lib/useCases/getContext/index.cjs +19 -0
- package/lib/useCases/getContext/index.d.ts +9 -0
- package/lib/useCases/getContext/index.js +17 -0
- package/lib/useCases/handleAuthRoutes/HandleAuthRoutesError.cjs +21 -0
- package/lib/useCases/handleAuthRoutes/HandleAuthRoutesError.d.ts +9 -0
- package/lib/useCases/handleAuthRoutes/HandleAuthRoutesError.js +19 -0
- package/lib/useCases/handleAuthRoutes/index.cjs +44 -0
- package/lib/useCases/handleAuthRoutes/index.d.ts +15 -0
- package/lib/useCases/handleAuthRoutes/index.js +42 -0
- package/lib/useCases/handleSignIn/HandleSignInController.cjs +31 -0
- package/lib/useCases/handleSignIn/HandleSignInController.d.ts +15 -0
- package/lib/useCases/handleSignIn/HandleSignInController.js +29 -0
- package/lib/useCases/handleSignIn/HandleSignInController.spec.d.ts +1 -0
- package/lib/useCases/handleSignIn/HandleSignInUseCase.cjs +17 -0
- package/lib/useCases/handleSignIn/HandleSignInUseCase.d.ts +16 -0
- package/lib/useCases/handleSignIn/HandleSignInUseCase.js +15 -0
- package/lib/useCases/handleSignIn/HandleSignInUseCase.spec.d.ts +1 -0
- package/lib/useCases/handleSignIn/index.cjs +19 -0
- package/lib/useCases/handleSignIn/index.d.ts +11 -0
- package/lib/useCases/handleSignIn/index.js +17 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackController.cjs +42 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackController.d.ts +15 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackController.js +40 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackController.spec.d.ts +1 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackError.cjs +17 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackError.d.ts +8 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackError.js +15 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackUseCase.cjs +16 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackUseCase.d.ts +15 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackUseCase.js +14 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackUseCase.spec.d.ts +1 -0
- package/lib/useCases/handleSignInCallback/index.cjs +19 -0
- package/lib/useCases/handleSignInCallback/index.d.ts +11 -0
- package/lib/useCases/handleSignInCallback/index.js +17 -0
- package/lib/useCases/handleSignOut/HandleSignOutController.cjs +34 -0
- package/lib/useCases/handleSignOut/HandleSignOutController.d.ts +15 -0
- package/lib/useCases/handleSignOut/HandleSignOutController.js +32 -0
- package/lib/useCases/handleSignOut/HandleSignOutController.spec.d.ts +1 -0
- package/lib/useCases/handleSignOut/HandleSignOutError.cjs +17 -0
- package/lib/useCases/handleSignOut/HandleSignOutError.d.ts +8 -0
- package/lib/useCases/handleSignOut/HandleSignOutError.js +15 -0
- package/lib/useCases/handleSignOut/HandleSignOutUseCase.cjs +17 -0
- package/lib/useCases/handleSignOut/HandleSignOutUseCase.d.ts +16 -0
- package/lib/useCases/handleSignOut/HandleSignOutUseCase.js +15 -0
- package/lib/useCases/handleSignOut/HandleSignOutUseCase.spec.d.ts +1 -0
- package/lib/useCases/handleSignOut/index.cjs +19 -0
- package/lib/useCases/handleSignOut/index.d.ts +11 -0
- package/lib/useCases/handleSignOut/index.js +17 -0
- package/package.json +29 -34
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/module.d.mts +0 -29
- package/lib/module.mjs +0 -480
- package/lib/module.mjs.map +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node = require('@remix-run/node');
|
|
4
|
+
var getCookieHeaderFromRequest = require('../../framework/get-cookie-header-from-request.cjs');
|
|
5
|
+
|
|
6
|
+
class HandleSignInController {
|
|
7
|
+
static { this.fromDto = (dto) => new HandleSignInController({
|
|
8
|
+
useCase: dto.useCase,
|
|
9
|
+
redirectUri: dto.redirectUri,
|
|
10
|
+
}); }
|
|
11
|
+
constructor(properties) {
|
|
12
|
+
this.properties = properties;
|
|
13
|
+
this.useCase = this.properties.useCase;
|
|
14
|
+
this.redirectUri = this.properties.redirectUri;
|
|
15
|
+
this.execute = async (request) => {
|
|
16
|
+
const cookieHeader = getCookieHeaderFromRequest.getCookieHeaderFromRequest(request);
|
|
17
|
+
const { redirectUri } = this;
|
|
18
|
+
const result = await this.useCase({
|
|
19
|
+
cookieHeader: cookieHeader ?? undefined,
|
|
20
|
+
redirectUri,
|
|
21
|
+
});
|
|
22
|
+
return node.redirect(result.navigateToUrl, {
|
|
23
|
+
headers: {
|
|
24
|
+
'Set-Cookie': result.cookieHeader,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.HandleSignInController = HandleSignInController;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TypedResponse } from '@remix-run/node';
|
|
2
|
+
import type { HandleSignInUseCase } from './HandleSignInUseCase.js';
|
|
3
|
+
type HandleSignInControllerDto = {
|
|
4
|
+
readonly redirectUri: string;
|
|
5
|
+
readonly useCase: HandleSignInUseCase;
|
|
6
|
+
};
|
|
7
|
+
export declare class HandleSignInController {
|
|
8
|
+
private readonly properties;
|
|
9
|
+
static readonly fromDto: (dto: HandleSignInControllerDto) => HandleSignInController;
|
|
10
|
+
private readonly useCase;
|
|
11
|
+
private readonly redirectUri;
|
|
12
|
+
private constructor();
|
|
13
|
+
readonly execute: (request: Request) => Promise<TypedResponse<never>>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { redirect } from '@remix-run/node';
|
|
2
|
+
import { getCookieHeaderFromRequest } from '../../framework/get-cookie-header-from-request.js';
|
|
3
|
+
|
|
4
|
+
class HandleSignInController {
|
|
5
|
+
static { this.fromDto = (dto) => new HandleSignInController({
|
|
6
|
+
useCase: dto.useCase,
|
|
7
|
+
redirectUri: dto.redirectUri,
|
|
8
|
+
}); }
|
|
9
|
+
constructor(properties) {
|
|
10
|
+
this.properties = properties;
|
|
11
|
+
this.useCase = this.properties.useCase;
|
|
12
|
+
this.redirectUri = this.properties.redirectUri;
|
|
13
|
+
this.execute = async (request) => {
|
|
14
|
+
const cookieHeader = getCookieHeaderFromRequest(request);
|
|
15
|
+
const { redirectUri } = this;
|
|
16
|
+
const result = await this.useCase({
|
|
17
|
+
cookieHeader: cookieHeader ?? undefined,
|
|
18
|
+
redirectUri,
|
|
19
|
+
});
|
|
20
|
+
return redirect(result.navigateToUrl, {
|
|
21
|
+
headers: {
|
|
22
|
+
'Set-Cookie': result.cookieHeader,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { HandleSignInController };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const makeHandleSignInUseCase = (deps) => async (request) => {
|
|
4
|
+
const { sessionStorage, createLogtoAdapter } = deps;
|
|
5
|
+
const session = await sessionStorage.getSession(request.cookieHeader);
|
|
6
|
+
const logto = createLogtoAdapter(session);
|
|
7
|
+
const response = await logto.handleSignIn({
|
|
8
|
+
redirectUri: request.redirectUri,
|
|
9
|
+
});
|
|
10
|
+
const cookieHeader = await sessionStorage.commitSession(response.session);
|
|
11
|
+
return {
|
|
12
|
+
cookieHeader,
|
|
13
|
+
navigateToUrl: response.navigateToUrl,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.makeHandleSignInUseCase = makeHandleSignInUseCase;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SessionStorage } from '@remix-run/node';
|
|
2
|
+
import type { CreateLogtoAdapter } from '../../infrastructure/logto/index.js';
|
|
3
|
+
type SignInRequest = {
|
|
4
|
+
readonly cookieHeader: string | undefined;
|
|
5
|
+
readonly redirectUri: string;
|
|
6
|
+
};
|
|
7
|
+
type SignInResponse = {
|
|
8
|
+
readonly cookieHeader: string;
|
|
9
|
+
readonly navigateToUrl: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const makeHandleSignInUseCase: (deps: {
|
|
12
|
+
createLogtoAdapter: CreateLogtoAdapter;
|
|
13
|
+
sessionStorage: SessionStorage;
|
|
14
|
+
}) => (request: SignInRequest) => Promise<SignInResponse>;
|
|
15
|
+
export type HandleSignInUseCase = ReturnType<typeof makeHandleSignInUseCase>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const makeHandleSignInUseCase = (deps) => async (request) => {
|
|
2
|
+
const { sessionStorage, createLogtoAdapter } = deps;
|
|
3
|
+
const session = await sessionStorage.getSession(request.cookieHeader);
|
|
4
|
+
const logto = createLogtoAdapter(session);
|
|
5
|
+
const response = await logto.handleSignIn({
|
|
6
|
+
redirectUri: request.redirectUri,
|
|
7
|
+
});
|
|
8
|
+
const cookieHeader = await sessionStorage.commitSession(response.session);
|
|
9
|
+
return {
|
|
10
|
+
cookieHeader,
|
|
11
|
+
navigateToUrl: response.navigateToUrl,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { makeHandleSignInUseCase };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var HandleSignInController = require('./HandleSignInController.cjs');
|
|
4
|
+
var HandleSignInUseCase = require('./HandleSignInUseCase.cjs');
|
|
5
|
+
|
|
6
|
+
const makeHandleSignIn = (dto, deps) => async (request) => {
|
|
7
|
+
const { createLogtoAdapter, sessionStorage } = deps;
|
|
8
|
+
const useCase = HandleSignInUseCase.makeHandleSignInUseCase({
|
|
9
|
+
createLogtoAdapter,
|
|
10
|
+
sessionStorage,
|
|
11
|
+
});
|
|
12
|
+
const controller = HandleSignInController.HandleSignInController.fromDto({
|
|
13
|
+
useCase,
|
|
14
|
+
redirectUri: dto.redirectBackTo,
|
|
15
|
+
});
|
|
16
|
+
return controller.execute(request);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.makeHandleSignIn = makeHandleSignIn;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SessionStorage } from '@remix-run/node';
|
|
2
|
+
import type { CreateLogtoAdapter } from '../../infrastructure/logto/index.js';
|
|
3
|
+
type HandleSignInDto = {
|
|
4
|
+
readonly redirectBackTo: string;
|
|
5
|
+
};
|
|
6
|
+
type HandleSignInDeps = {
|
|
7
|
+
readonly createLogtoAdapter: CreateLogtoAdapter;
|
|
8
|
+
readonly sessionStorage: SessionStorage;
|
|
9
|
+
};
|
|
10
|
+
export declare const makeHandleSignIn: (dto: HandleSignInDto, deps: HandleSignInDeps) => (request: Request) => Promise<import("@remix-run/node").TypedResponse<never>>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HandleSignInController } from './HandleSignInController.js';
|
|
2
|
+
import { makeHandleSignInUseCase } from './HandleSignInUseCase.js';
|
|
3
|
+
|
|
4
|
+
const makeHandleSignIn = (dto, deps) => async (request) => {
|
|
5
|
+
const { createLogtoAdapter, sessionStorage } = deps;
|
|
6
|
+
const useCase = makeHandleSignInUseCase({
|
|
7
|
+
createLogtoAdapter,
|
|
8
|
+
sessionStorage,
|
|
9
|
+
});
|
|
10
|
+
const controller = HandleSignInController.fromDto({
|
|
11
|
+
useCase,
|
|
12
|
+
redirectUri: dto.redirectBackTo,
|
|
13
|
+
});
|
|
14
|
+
return controller.execute(request);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { makeHandleSignIn };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node = require('@remix-run/node');
|
|
4
|
+
var getCookieHeaderFromRequest = require('../../framework/get-cookie-header-from-request.cjs');
|
|
5
|
+
var HandleSignInCallbackError = require('./HandleSignInCallbackError.cjs');
|
|
6
|
+
|
|
7
|
+
class HandleSignInCallbackController {
|
|
8
|
+
static { this.fromDto = (dto) => new HandleSignInCallbackController({
|
|
9
|
+
useCase: dto.useCase,
|
|
10
|
+
redirectUri: dto.redirectUri,
|
|
11
|
+
}); }
|
|
12
|
+
constructor(properties) {
|
|
13
|
+
this.properties = properties;
|
|
14
|
+
this.useCase = this.properties.useCase;
|
|
15
|
+
this.redirectUri = this.properties.redirectUri;
|
|
16
|
+
this.execute = async (request) => {
|
|
17
|
+
const cookieHeader = getCookieHeaderFromRequest.getCookieHeaderFromRequest(request);
|
|
18
|
+
if (!cookieHeader) {
|
|
19
|
+
throw HandleSignInCallbackError.HandleSignInCallbackError.becauseNoCookieHeaderPresent();
|
|
20
|
+
}
|
|
21
|
+
// In some scenarios, like performing the sign-in callback within a Gitpod
|
|
22
|
+
// environment, the load balancer rewrites the URL and uses `http` as the
|
|
23
|
+
// protocol. Here, we make sure that when the `x-forwarded-proto` HTTP header
|
|
24
|
+
// is present, we will replace `http` with `https` in the `callbackUri`.
|
|
25
|
+
const isForwardedHttpsTraffic = request.headers.get('x-forwarded-proto') === 'https';
|
|
26
|
+
const callbackUri = isForwardedHttpsTraffic
|
|
27
|
+
? request.url.replace('http', 'https')
|
|
28
|
+
: request.url;
|
|
29
|
+
const result = await this.useCase({
|
|
30
|
+
cookieHeader,
|
|
31
|
+
callbackUri,
|
|
32
|
+
});
|
|
33
|
+
return node.redirect(this.redirectUri, {
|
|
34
|
+
headers: {
|
|
35
|
+
'Set-Cookie': result.cookieHeader,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.HandleSignInCallbackController = HandleSignInCallbackController;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TypedResponse } from '@remix-run/node';
|
|
2
|
+
import type { HandleSignInCallbackUseCase } from './HandleSignInCallbackUseCase.js';
|
|
3
|
+
type HandleSignInCallbackControllerDto = {
|
|
4
|
+
readonly useCase: HandleSignInCallbackUseCase;
|
|
5
|
+
readonly redirectUri: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class HandleSignInCallbackController {
|
|
8
|
+
private readonly properties;
|
|
9
|
+
static readonly fromDto: (dto: HandleSignInCallbackControllerDto) => HandleSignInCallbackController;
|
|
10
|
+
private readonly useCase;
|
|
11
|
+
private readonly redirectUri;
|
|
12
|
+
private constructor();
|
|
13
|
+
readonly execute: (request: Request) => Promise<TypedResponse<never>>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { redirect } from '@remix-run/node';
|
|
2
|
+
import { getCookieHeaderFromRequest } from '../../framework/get-cookie-header-from-request.js';
|
|
3
|
+
import { HandleSignInCallbackError } from './HandleSignInCallbackError.js';
|
|
4
|
+
|
|
5
|
+
class HandleSignInCallbackController {
|
|
6
|
+
static { this.fromDto = (dto) => new HandleSignInCallbackController({
|
|
7
|
+
useCase: dto.useCase,
|
|
8
|
+
redirectUri: dto.redirectUri,
|
|
9
|
+
}); }
|
|
10
|
+
constructor(properties) {
|
|
11
|
+
this.properties = properties;
|
|
12
|
+
this.useCase = this.properties.useCase;
|
|
13
|
+
this.redirectUri = this.properties.redirectUri;
|
|
14
|
+
this.execute = async (request) => {
|
|
15
|
+
const cookieHeader = getCookieHeaderFromRequest(request);
|
|
16
|
+
if (!cookieHeader) {
|
|
17
|
+
throw HandleSignInCallbackError.becauseNoCookieHeaderPresent();
|
|
18
|
+
}
|
|
19
|
+
// In some scenarios, like performing the sign-in callback within a Gitpod
|
|
20
|
+
// environment, the load balancer rewrites the URL and uses `http` as the
|
|
21
|
+
// protocol. Here, we make sure that when the `x-forwarded-proto` HTTP header
|
|
22
|
+
// is present, we will replace `http` with `https` in the `callbackUri`.
|
|
23
|
+
const isForwardedHttpsTraffic = request.headers.get('x-forwarded-proto') === 'https';
|
|
24
|
+
const callbackUri = isForwardedHttpsTraffic
|
|
25
|
+
? request.url.replace('http', 'https')
|
|
26
|
+
: request.url;
|
|
27
|
+
const result = await this.useCase({
|
|
28
|
+
cookieHeader,
|
|
29
|
+
callbackUri,
|
|
30
|
+
});
|
|
31
|
+
return redirect(this.redirectUri, {
|
|
32
|
+
headers: {
|
|
33
|
+
'Set-Cookie': result.cookieHeader,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { HandleSignInCallbackController };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class HandleSignInCallbackError extends Error {
|
|
4
|
+
static { this.becauseNoCookieHeaderPresent = () => new HandleSignInCallbackError({
|
|
5
|
+
code: 1_665_388_541,
|
|
6
|
+
message: `The authentication sign-in callback route can't be accessed without a valid cookie.`,
|
|
7
|
+
}); }
|
|
8
|
+
constructor(properties) {
|
|
9
|
+
super(`#[${properties.code}] ${properties.message}`);
|
|
10
|
+
this.properties = properties;
|
|
11
|
+
this.code = this.properties.code;
|
|
12
|
+
this.cause = this.properties.cause;
|
|
13
|
+
this.plainMessage = this.properties.message;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.HandleSignInCallbackError = HandleSignInCallbackError;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class HandleSignInCallbackError extends Error {
|
|
2
|
+
private readonly properties;
|
|
3
|
+
static readonly becauseNoCookieHeaderPresent: () => HandleSignInCallbackError;
|
|
4
|
+
readonly code: number;
|
|
5
|
+
readonly cause: Error | undefined;
|
|
6
|
+
readonly plainMessage: string;
|
|
7
|
+
private constructor();
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class HandleSignInCallbackError extends Error {
|
|
2
|
+
static { this.becauseNoCookieHeaderPresent = () => new HandleSignInCallbackError({
|
|
3
|
+
code: 1_665_388_541,
|
|
4
|
+
message: `The authentication sign-in callback route can't be accessed without a valid cookie.`,
|
|
5
|
+
}); }
|
|
6
|
+
constructor(properties) {
|
|
7
|
+
super(`#[${properties.code}] ${properties.message}`);
|
|
8
|
+
this.properties = properties;
|
|
9
|
+
this.code = this.properties.code;
|
|
10
|
+
this.cause = this.properties.cause;
|
|
11
|
+
this.plainMessage = this.properties.message;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { HandleSignInCallbackError };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const makeHandleSignInCallbackUseCase = (deps) => async (request) => {
|
|
4
|
+
const { sessionStorage, createLogtoAdapter } = deps;
|
|
5
|
+
const session = await sessionStorage.getSession(request.cookieHeader);
|
|
6
|
+
const logto = createLogtoAdapter(session);
|
|
7
|
+
const response = await logto.handleSignInCallback({
|
|
8
|
+
callbackUri: request.callbackUri,
|
|
9
|
+
});
|
|
10
|
+
const cookieHeader = await sessionStorage.commitSession(response.session);
|
|
11
|
+
return {
|
|
12
|
+
cookieHeader,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.makeHandleSignInCallbackUseCase = makeHandleSignInCallbackUseCase;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SessionStorage } from '@remix-run/node';
|
|
2
|
+
import type { CreateLogtoAdapter } from '../../infrastructure/logto/index.js';
|
|
3
|
+
type SignInCallbackRequest = {
|
|
4
|
+
readonly cookieHeader: string;
|
|
5
|
+
readonly callbackUri: string;
|
|
6
|
+
};
|
|
7
|
+
type SignInCallbackResponse = {
|
|
8
|
+
readonly cookieHeader: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const makeHandleSignInCallbackUseCase: (deps: {
|
|
11
|
+
createLogtoAdapter: CreateLogtoAdapter;
|
|
12
|
+
sessionStorage: SessionStorage;
|
|
13
|
+
}) => (request: SignInCallbackRequest) => Promise<SignInCallbackResponse>;
|
|
14
|
+
export type HandleSignInCallbackUseCase = ReturnType<typeof makeHandleSignInCallbackUseCase>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const makeHandleSignInCallbackUseCase = (deps) => async (request) => {
|
|
2
|
+
const { sessionStorage, createLogtoAdapter } = deps;
|
|
3
|
+
const session = await sessionStorage.getSession(request.cookieHeader);
|
|
4
|
+
const logto = createLogtoAdapter(session);
|
|
5
|
+
const response = await logto.handleSignInCallback({
|
|
6
|
+
callbackUri: request.callbackUri,
|
|
7
|
+
});
|
|
8
|
+
const cookieHeader = await sessionStorage.commitSession(response.session);
|
|
9
|
+
return {
|
|
10
|
+
cookieHeader,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { makeHandleSignInCallbackUseCase };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var HandleSignInCallbackController = require('./HandleSignInCallbackController.cjs');
|
|
4
|
+
var HandleSignInCallbackUseCase = require('./HandleSignInCallbackUseCase.cjs');
|
|
5
|
+
|
|
6
|
+
const makeHandleSignInCallback = (dto, deps) => async (request) => {
|
|
7
|
+
const { createLogtoAdapter, sessionStorage } = deps;
|
|
8
|
+
const useCase = HandleSignInCallbackUseCase.makeHandleSignInCallbackUseCase({
|
|
9
|
+
createLogtoAdapter,
|
|
10
|
+
sessionStorage,
|
|
11
|
+
});
|
|
12
|
+
const controller = HandleSignInCallbackController.HandleSignInCallbackController.fromDto({
|
|
13
|
+
useCase,
|
|
14
|
+
redirectUri: dto.redirectBackTo,
|
|
15
|
+
});
|
|
16
|
+
return controller.execute(request);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.makeHandleSignInCallback = makeHandleSignInCallback;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SessionStorage } from '@remix-run/node';
|
|
2
|
+
import type { CreateLogtoAdapter } from '../../infrastructure/logto/index.js';
|
|
3
|
+
type HandleSignInCallbackDto = {
|
|
4
|
+
readonly redirectBackTo: string;
|
|
5
|
+
};
|
|
6
|
+
type HandleSignInCallbackDeps = {
|
|
7
|
+
readonly createLogtoAdapter: CreateLogtoAdapter;
|
|
8
|
+
readonly sessionStorage: SessionStorage;
|
|
9
|
+
};
|
|
10
|
+
export declare const makeHandleSignInCallback: (dto: HandleSignInCallbackDto, deps: HandleSignInCallbackDeps) => (request: Request) => Promise<import("@remix-run/node").TypedResponse<never>>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HandleSignInCallbackController } from './HandleSignInCallbackController.js';
|
|
2
|
+
import { makeHandleSignInCallbackUseCase } from './HandleSignInCallbackUseCase.js';
|
|
3
|
+
|
|
4
|
+
const makeHandleSignInCallback = (dto, deps) => async (request) => {
|
|
5
|
+
const { createLogtoAdapter, sessionStorage } = deps;
|
|
6
|
+
const useCase = makeHandleSignInCallbackUseCase({
|
|
7
|
+
createLogtoAdapter,
|
|
8
|
+
sessionStorage,
|
|
9
|
+
});
|
|
10
|
+
const controller = HandleSignInCallbackController.fromDto({
|
|
11
|
+
useCase,
|
|
12
|
+
redirectUri: dto.redirectBackTo,
|
|
13
|
+
});
|
|
14
|
+
return controller.execute(request);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { makeHandleSignInCallback };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node = require('@remix-run/node');
|
|
4
|
+
var getCookieHeaderFromRequest = require('../../framework/get-cookie-header-from-request.cjs');
|
|
5
|
+
var HandleSignOutError = require('./HandleSignOutError.cjs');
|
|
6
|
+
|
|
7
|
+
class HandleSignOutController {
|
|
8
|
+
static { this.fromDto = (dto) => new HandleSignOutController({
|
|
9
|
+
useCase: dto.useCase,
|
|
10
|
+
redirectUri: dto.redirectUri,
|
|
11
|
+
}); }
|
|
12
|
+
constructor(properties) {
|
|
13
|
+
this.properties = properties;
|
|
14
|
+
this.useCase = this.properties.useCase;
|
|
15
|
+
this.redirectUri = this.properties.redirectUri;
|
|
16
|
+
this.execute = async (request) => {
|
|
17
|
+
const cookieHeader = getCookieHeaderFromRequest.getCookieHeaderFromRequest(request);
|
|
18
|
+
if (!cookieHeader) {
|
|
19
|
+
throw HandleSignOutError.HandleSignOutError.becauseNoCookieHeaderPresent();
|
|
20
|
+
}
|
|
21
|
+
const result = await this.useCase({
|
|
22
|
+
cookieHeader,
|
|
23
|
+
redirectUri: this.redirectUri,
|
|
24
|
+
});
|
|
25
|
+
return node.redirect(result.navigateToUrl, {
|
|
26
|
+
headers: {
|
|
27
|
+
'Set-Cookie': result.cookieHeader,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.HandleSignOutController = HandleSignOutController;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TypedResponse } from '@remix-run/node';
|
|
2
|
+
import type { HandleSignOutUseCase } from './HandleSignOutUseCase.js';
|
|
3
|
+
type HandleSignOutControllerDto = {
|
|
4
|
+
readonly useCase: HandleSignOutUseCase;
|
|
5
|
+
readonly redirectUri: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class HandleSignOutController {
|
|
8
|
+
private readonly properties;
|
|
9
|
+
static readonly fromDto: (dto: HandleSignOutControllerDto) => HandleSignOutController;
|
|
10
|
+
private readonly useCase;
|
|
11
|
+
private readonly redirectUri;
|
|
12
|
+
private constructor();
|
|
13
|
+
readonly execute: (request: Request) => Promise<TypedResponse<never>>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { redirect } from '@remix-run/node';
|
|
2
|
+
import { getCookieHeaderFromRequest } from '../../framework/get-cookie-header-from-request.js';
|
|
3
|
+
import { HandleSignOutError } from './HandleSignOutError.js';
|
|
4
|
+
|
|
5
|
+
class HandleSignOutController {
|
|
6
|
+
static { this.fromDto = (dto) => new HandleSignOutController({
|
|
7
|
+
useCase: dto.useCase,
|
|
8
|
+
redirectUri: dto.redirectUri,
|
|
9
|
+
}); }
|
|
10
|
+
constructor(properties) {
|
|
11
|
+
this.properties = properties;
|
|
12
|
+
this.useCase = this.properties.useCase;
|
|
13
|
+
this.redirectUri = this.properties.redirectUri;
|
|
14
|
+
this.execute = async (request) => {
|
|
15
|
+
const cookieHeader = getCookieHeaderFromRequest(request);
|
|
16
|
+
if (!cookieHeader) {
|
|
17
|
+
throw HandleSignOutError.becauseNoCookieHeaderPresent();
|
|
18
|
+
}
|
|
19
|
+
const result = await this.useCase({
|
|
20
|
+
cookieHeader,
|
|
21
|
+
redirectUri: this.redirectUri,
|
|
22
|
+
});
|
|
23
|
+
return redirect(result.navigateToUrl, {
|
|
24
|
+
headers: {
|
|
25
|
+
'Set-Cookie': result.cookieHeader,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { HandleSignOutController };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class HandleSignOutError extends Error {
|
|
4
|
+
static { this.becauseNoCookieHeaderPresent = () => new HandleSignOutError({
|
|
5
|
+
code: 1_665_388_713,
|
|
6
|
+
message: `The authentication sign-out route can't be accessed without a valid cookie.`,
|
|
7
|
+
}); }
|
|
8
|
+
constructor(properties) {
|
|
9
|
+
super(`#[${properties.code}] ${properties.message}`);
|
|
10
|
+
this.properties = properties;
|
|
11
|
+
this.code = this.properties.code;
|
|
12
|
+
this.cause = this.properties.cause;
|
|
13
|
+
this.plainMessage = this.properties.message;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.HandleSignOutError = HandleSignOutError;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class HandleSignOutError extends Error {
|
|
2
|
+
private readonly properties;
|
|
3
|
+
static readonly becauseNoCookieHeaderPresent: () => HandleSignOutError;
|
|
4
|
+
readonly code: number;
|
|
5
|
+
readonly cause: Error | undefined;
|
|
6
|
+
readonly plainMessage: string;
|
|
7
|
+
private constructor();
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class HandleSignOutError extends Error {
|
|
2
|
+
static { this.becauseNoCookieHeaderPresent = () => new HandleSignOutError({
|
|
3
|
+
code: 1_665_388_713,
|
|
4
|
+
message: `The authentication sign-out route can't be accessed without a valid cookie.`,
|
|
5
|
+
}); }
|
|
6
|
+
constructor(properties) {
|
|
7
|
+
super(`#[${properties.code}] ${properties.message}`);
|
|
8
|
+
this.properties = properties;
|
|
9
|
+
this.code = this.properties.code;
|
|
10
|
+
this.cause = this.properties.cause;
|
|
11
|
+
this.plainMessage = this.properties.message;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { HandleSignOutError };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const makeHandleSignOutUseCase = (deps) => async (request) => {
|
|
4
|
+
const { sessionStorage, createLogtoAdapter } = deps;
|
|
5
|
+
const session = await sessionStorage.getSession(request.cookieHeader);
|
|
6
|
+
const logto = createLogtoAdapter(session);
|
|
7
|
+
const response = await logto.handleSignOut({
|
|
8
|
+
redirectUri: request.redirectUri,
|
|
9
|
+
});
|
|
10
|
+
const cookieHeader = await sessionStorage.destroySession(session);
|
|
11
|
+
return {
|
|
12
|
+
cookieHeader,
|
|
13
|
+
navigateToUrl: response.navigateToUrl,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.makeHandleSignOutUseCase = makeHandleSignOutUseCase;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SessionStorage } from '@remix-run/node';
|
|
2
|
+
import type { CreateLogtoAdapter } from '../../infrastructure/logto/index.js';
|
|
3
|
+
type SignOutRequest = {
|
|
4
|
+
readonly cookieHeader: string | undefined;
|
|
5
|
+
redirectUri: string;
|
|
6
|
+
};
|
|
7
|
+
type SignOutResponse = {
|
|
8
|
+
cookieHeader: string;
|
|
9
|
+
readonly navigateToUrl: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const makeHandleSignOutUseCase: (deps: {
|
|
12
|
+
createLogtoAdapter: CreateLogtoAdapter;
|
|
13
|
+
sessionStorage: SessionStorage;
|
|
14
|
+
}) => (request: SignOutRequest) => Promise<SignOutResponse>;
|
|
15
|
+
export type HandleSignOutUseCase = ReturnType<typeof makeHandleSignOutUseCase>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const makeHandleSignOutUseCase = (deps) => async (request) => {
|
|
2
|
+
const { sessionStorage, createLogtoAdapter } = deps;
|
|
3
|
+
const session = await sessionStorage.getSession(request.cookieHeader);
|
|
4
|
+
const logto = createLogtoAdapter(session);
|
|
5
|
+
const response = await logto.handleSignOut({
|
|
6
|
+
redirectUri: request.redirectUri,
|
|
7
|
+
});
|
|
8
|
+
const cookieHeader = await sessionStorage.destroySession(session);
|
|
9
|
+
return {
|
|
10
|
+
cookieHeader,
|
|
11
|
+
navigateToUrl: response.navigateToUrl,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { makeHandleSignOutUseCase };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var HandleSignOutController = require('./HandleSignOutController.cjs');
|
|
4
|
+
var HandleSignOutUseCase = require('./HandleSignOutUseCase.cjs');
|
|
5
|
+
|
|
6
|
+
const makeHandleSignOut = (dto, deps) => async (request) => {
|
|
7
|
+
const { createLogtoAdapter, sessionStorage } = deps;
|
|
8
|
+
const useCase = HandleSignOutUseCase.makeHandleSignOutUseCase({
|
|
9
|
+
createLogtoAdapter,
|
|
10
|
+
sessionStorage,
|
|
11
|
+
});
|
|
12
|
+
const controller = HandleSignOutController.HandleSignOutController.fromDto({
|
|
13
|
+
useCase,
|
|
14
|
+
redirectUri: dto.redirectBackTo,
|
|
15
|
+
});
|
|
16
|
+
return controller.execute(request);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.makeHandleSignOut = makeHandleSignOut;
|