diff --git a/packages/core/src/saml-applications/libraries/consts.ts b/packages/core/src/saml-applications/libraries/consts.ts
new file mode 100644
index 000000000..cf8abae46
--- /dev/null
+++ b/packages/core/src/saml-applications/libraries/consts.ts
@@ -0,0 +1,22 @@
+export const samlLogInResponseTemplate = `
+
+ {Issuer}
+
+
+
+
+ {Issuer}
+
+ {NameID}
+
+
+
+
+
+
+ {Audience}
+
+
+ {AttributeStatement}
+
+`;
diff --git a/packages/core/src/saml-applications/routes/anonymous.ts b/packages/core/src/saml-applications/routes/anonymous.ts
index b3b7ab646..98e3d99a9 100644
--- a/packages/core/src/saml-applications/routes/anonymous.ts
+++ b/packages/core/src/saml-applications/routes/anonymous.ts
@@ -1,8 +1,5 @@
-import { parseJson } from '@logto/connector-kit';
import { tryThat } from '@silverhand/essentials';
-import camelcaseKeys from 'camelcase-keys';
-import { got } from 'got';
-import saml from 'samlify';
+import * as saml from 'samlify';
import { z } from 'zod';
import RequestError from '#src/errors/RequestError/index.js';
@@ -10,10 +7,11 @@ import koaGuard from '#src/middleware/koa-guard.js';
import type { AnonymousRouter, RouterInitArgs } from '#src/routes/types.js';
import { fetchOidcConfig, getUserInfo } from '#src/sso/OidcConnector/utils.js';
import { SsoConnectorError } from '#src/sso/types/error.js';
-import { oidcTokenResponseGuard } from '#src/sso/types/oidc.js';
import assertThat from '#src/utils/assert-that.js';
-import { createSamlTemplateCallback, samlLogInResponseTemplate } from './utils.js';
+import { samlLogInResponseTemplate } from '../libraries/consts.js';
+
+import { exchangeAuthorizationCode, generateAutoSubmitForm, createSamlResponse } from './utils.js';
const samlApplicationSignInCallbackQueryParametersGuard = z.union([
z.object({
@@ -97,41 +95,20 @@ export default function samlApplicationAnonymousRoutes
-
-
-
-
-