mirror of
https://github.com/hanzoai/sign.git
synced 2026-11-02 23:26:15 +00:00
- Add HanzoAuthOptions to auth config (OIDC via hanzo.id) - Add /authorize/hanzo and /callback/hanzo routes - Add authClient.hanzo.signIn() client method - Add "Sign in with Hanzo" button to sign-in form (first SSO option) - Add IS_HANZO_SSO_ENABLED constant - Env vars: HANZO_IAM_URL, HANZO_IAM_CLIENT_ID, HANZO_IAM_CLIENT_SECRET
83 lines
2.2 KiB
TypeScript
83 lines
2.2 KiB
TypeScript
import { sValidator } from '@hono/standard-validator';
|
|
import { Hono } from 'hono';
|
|
import { z } from 'zod';
|
|
|
|
import { GoogleAuthOptions, HanzoAuthOptions, MicrosoftAuthOptions, OidcAuthOptions } from '../config';
|
|
import { handleOAuthAuthorizeUrl } from '../lib/utils/handle-oauth-authorize-url';
|
|
import { getOrganisationAuthenticationPortalOptions } from '../lib/utils/organisation-portal';
|
|
import type { HonoAuthContext } from '../types/context';
|
|
|
|
const ZOAuthAuthorizeSchema = z.object({
|
|
redirectPath: z.string().optional(),
|
|
});
|
|
|
|
export const oauthRoute = new Hono<HonoAuthContext>()
|
|
/**
|
|
* Google authorize endpoint.
|
|
*/
|
|
.post('/authorize/google', sValidator('json', ZOAuthAuthorizeSchema), async (c) => {
|
|
const { redirectPath } = c.req.valid('json');
|
|
|
|
return handleOAuthAuthorizeUrl({
|
|
c,
|
|
clientOptions: GoogleAuthOptions,
|
|
redirectPath,
|
|
});
|
|
})
|
|
|
|
/**
|
|
* Microsoft authorize endpoint.
|
|
*/
|
|
.post('/authorize/microsoft', sValidator('json', ZOAuthAuthorizeSchema), async (c) => {
|
|
const { redirectPath } = c.req.valid('json');
|
|
|
|
return handleOAuthAuthorizeUrl({
|
|
c,
|
|
clientOptions: MicrosoftAuthOptions,
|
|
redirectPath,
|
|
});
|
|
})
|
|
|
|
/**
|
|
* Hanzo IAM authorize endpoint.
|
|
*/
|
|
.post('/authorize/hanzo', sValidator('json', ZOAuthAuthorizeSchema), async (c) => {
|
|
const { redirectPath } = c.req.valid('json');
|
|
|
|
return handleOAuthAuthorizeUrl({
|
|
c,
|
|
clientOptions: HanzoAuthOptions,
|
|
redirectPath,
|
|
});
|
|
})
|
|
|
|
/**
|
|
* OIDC authorize endpoint.
|
|
*/
|
|
.post('/authorize/oidc', sValidator('json', ZOAuthAuthorizeSchema), async (c) => {
|
|
const { redirectPath } = c.req.valid('json');
|
|
|
|
return handleOAuthAuthorizeUrl({
|
|
c,
|
|
clientOptions: OidcAuthOptions,
|
|
redirectPath,
|
|
});
|
|
})
|
|
/**
|
|
* Organisation OIDC authorize endpoint.
|
|
*/
|
|
.post('/authorize/oidc/org/:orgUrl', async (c) => {
|
|
const orgUrl = c.req.param('orgUrl');
|
|
|
|
const { clientOptions } = await getOrganisationAuthenticationPortalOptions({
|
|
type: 'url',
|
|
organisationUrl: orgUrl,
|
|
});
|
|
|
|
return await handleOAuthAuthorizeUrl({
|
|
c,
|
|
clientOptions,
|
|
prompt: 'select_account',
|
|
});
|
|
});
|