mirror of
https://github.com/logto-io/logto.git
synced 2025-02-17 22:04:19 -05:00
feat(core): enable pass redirectUri when sign-in with social (#284)
This commit is contained in:
parent
2109b7be31
commit
ddd695dd33
2 changed files with 10 additions and 9 deletions
|
@ -1,10 +1,6 @@
|
|||
import { Context } from 'koa';
|
||||
import { InteractionResults, Provider } from 'oidc-provider';
|
||||
|
||||
// TODO: change this after frontend is ready.
|
||||
// Should combine baseUrl(domain) from database with a 'callback' endpoint.
|
||||
export const connectorRedirectUrl = 'https://logto.dev/callback';
|
||||
|
||||
export const assignInteractionResults = async (
|
||||
ctx: Context,
|
||||
provider: Provider,
|
||||
|
|
|
@ -10,7 +10,7 @@ import { object, string } from 'zod';
|
|||
import { getSocialConnectorInstanceById } from '@/connectors';
|
||||
import RequestError from '@/errors/RequestError';
|
||||
import { createPasscode, sendPasscode, verifyPasscode } from '@/lib/passcode';
|
||||
import { assignInteractionResults, connectorRedirectUrl } from '@/lib/session';
|
||||
import { assignInteractionResults } from '@/lib/session';
|
||||
import {
|
||||
findSocialRelatedUser,
|
||||
getUserInfoByAuthCode,
|
||||
|
@ -164,18 +164,23 @@ export default function sessionRoutes<T extends AnonymousRouter>(router: T, prov
|
|||
router.post(
|
||||
'/session/sign-in/social',
|
||||
koaGuard({
|
||||
body: object({ connectorId: string(), code: string().optional(), state: string() }),
|
||||
body: object({
|
||||
connectorId: string(),
|
||||
code: string().optional(),
|
||||
state: string(),
|
||||
redirectUri: string(),
|
||||
}),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const { connectorId, code, state } = ctx.guard.body;
|
||||
const { connectorId, code, state, redirectUri } = ctx.guard.body;
|
||||
ctx.userLog.connectorId = connectorId;
|
||||
ctx.userLog.type = UserLogType.SignInSocial;
|
||||
|
||||
if (!code) {
|
||||
assertThat(state, 'session.insufficient_info');
|
||||
assertThat(state && redirectUri, 'session.insufficient_info');
|
||||
const connector = await getSocialConnectorInstanceById(connectorId);
|
||||
assertThat(connector.connector.enabled, 'connector.not_enabled');
|
||||
const redirectTo = await connector.getAuthorizationUri(connectorRedirectUrl, state);
|
||||
const redirectTo = await connector.getAuthorizationUri(redirectUri, state);
|
||||
ctx.body = { redirectTo };
|
||||
|
||||
return next();
|
||||
|
|
Loading…
Add table
Reference in a new issue