Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: add IdP-initiated SSO support (#17927)

boojackff8617941e54
diff --git a/backend/generated-go/v1/auth_service.pb.go b/backend/generated-go/v1/auth_service.pb.go
index 536fa1fe29..d5097a3df7 100644
--- a/backend/generated-go/v1/auth_service.pb.go
+++ b/backend/generated-go/v1/auth_service.pb.go
@@ -265,7 +265,9 @@ func (x *OAuth2IdentityProviderContext) GetCode() string {
// OpenID Connect authentication context.
type OIDCIdentityProviderContext struct {
- state protoimpl.MessageState `protogen:"open.v1"`
+ state protoimpl.MessageState `protogen:"open.v1"`
+ // Authorization code from OIDC provider.
+ Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -300,6 +302,13 @@ func (*OIDCIdentityProviderContext) Descriptor() ([]byte, []int) {
return file_v1_auth_service_proto_rawDescGZIP(), []int{3}
}
+func (x *OIDCIdentityProviderContext) GetCode() string {
+ if x != nil {
+ return x.Code
+ }
+ return ""
+}
+
type LoginResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
// Access token for authenticated requests.
@@ -432,8 +441,9 @@ const file_v1_auth_service_proto_rawDesc = "" +
"\foidc_context\x18\x02 \x01(\v2(.bytebase.v1.OIDCIdentityProviderContextH\x00R\voidcContextB\t\n" +
"\acontext\"3\n" +
"\x1dOAuth2IdentityProviderContext\x12\x12\n" +
- "\x04code\x18\x01 \x01(\tR\x04code\"\x1d\n" +
- "\x1bOIDCIdentityProviderContext\"\xc0\x01\n" +
+ "\x04code\x18\x01 \x01(\tR\x04code\"1\n" +
+ "\x1bOIDCIdentityProviderContext\x12\x12\n" +
+ "\x04code\x18\x01 \x01(\tR\x04code\"\xc0\x01\n" +
"\rLoginResponse\x12\x14\n" +
"\x05token\x18\x01 \x01(\tR\x05token\x12)\n" +
"\x0emfa_temp_token\x18\x02 \x01(\tH\x00R\fmfaTempToken\x88\x01\x01\x124\n" +
diff --git a/backend/generated-go/v1/auth_service_equal.pb.go b/backend/generated-go/v1/auth_service_equal.pb.go
index cf008890ec..afd3beb916 100644
--- a/backend/generated-go/v1/auth_service_equal.pb.go
+++ b/backend/generated-go/v1/auth_service_equal.pb.go
@@ -73,6 +73,9 @@ func (x *OIDCIdentityProviderContext) Equal(y *OIDCIdentityProviderContext) bool
if x == nil || y == nil {
return x == nil && y == nil
}
+ if x.Code != y.Code {
+ return false
+ }
return true
}
diff --git a/frontend/src/router/auth.ts b/frontend/src/router/auth.ts
index a770596876..bb1f4e0d71 100644
--- a/frontend/src/router/auth.ts
+++ b/frontend/src/router/auth.ts
@@ -10,6 +10,7 @@ export const AUTH_PASSWORD_RESET_MODULE = "auth.password.reset";
export const AUTH_PASSWORD_FORGOT_MODULE = "auth.password.forgot";
export const AUTH_OAUTH_CALLBACK_MODULE = "auth.oauth.callback";
export const AUTH_OIDC_CALLBACK_MODULE = "auth.oidc.callback";
+export const AUTH_IDP_INIT_MODULE = "auth.idp.init";
export const AUTH_2FA_SETUP_MODULE = "auth.2fa.setup";
const authRoutes: RouteRecordRaw[] = [
@@ -55,6 +56,12 @@ const authRoutes: RouteRecordRaw[] = [
meta: { title: () => t("multi-factor.self") },
component: () => import("@/views/auth/MultiFactor.vue"),
},
+ {
+ path: "idp-init",
+ name: AUTH_IDP_INIT_MODULE,
+ meta: { title: () => "Initializing SSO" },
+ component: () => import("@/views/IdPInitiatedSSO.vue"),
+ },
],
},
{
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 747d4e761a..5165e31a2b 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -124,7 +124,22 @@ router.beforeEach((to, from, next) => {
authStore.isLoggedIn &&
!authStore.unauthenticatedOccurred
) {
- const redirect = (to.query["redirect"] as string) || "/";
+ // For IdP-initiated SSO, use relay_state parameter
+ // For other auth routes, use redirect parameter
+ const relayState = to.query["relay_state"] as string | undefined;
+ const redirectParam = to.query["redirect"] as string | undefined;
+
+ // Validate relay_state to prevent open redirect attacks
+ let redirect = "/";
+ if (relayState && typeof relayState === "string") {
+ // Only allow relative URLs, reject protocol-relative URLs (//)
+ if (relayState.startsWith("/") && !relayState.startsWith("//")) {
+ redirect = relayState;
+ }
+ } else if (redirectParam) {
+ redirect = redirectParam;
+ }
+
next(redirect);
return;
}
diff --git a/frontend/src/types/oauth.ts b/frontend/src/types/oauth.ts
index fc4eab0390..6887c5524f 100644
--- a/frontend/src/types/oauth.ts
+++ b/frontend/src/types/oauth.ts
@@ -1,10 +1,16 @@
+import type { IdentityProviderType } from "./proto-es/v1/idp_service_pb";
+
export type OAuthWindowEventPayload = {
error: string;
code: string;
};
export type OAuthState = {
+ token: string;
event: string;
popup?: boolean;
redirect?: string;
+ timestamp: number;
+ // IdP type to determine which context to use in callback (oauth2Context vs oidcContext)
+ idpType: IdentityProviderType;
};
diff --git a/frontend/src/types/proto-es/v1/auth_service_pb.d.ts b/frontend/src/types/proto-es/v1/auth_service_pb.d.ts
index 3ec0ced4f0..f775084626 100644
--- a/frontend/src/types/proto-es/v1/auth_service_pb.d.ts
+++ b/frontend/src/types/proto-es/v1/auth_service_pb.d.ts
@@ -140,6 +140,12 @@ export declare const OAuth2IdentityProviderContextSchema: GenMessage<OAuth2Ident
* @generated from message bytebase.v1.OIDCIdentityProviderContext
*/
export declare type OIDCIdentityProviderContext = Message<"bytebase.v1.OIDCIdentityProviderContext"> & {
+ /**
+ * Authorization code from OIDC provider.
+ *
+ * @generated from field: string code = 1;
+ */
+ code: string;
};
/**
diff --git a/frontend/src/types/proto-es/v1/auth_service_pb.js b/frontend/src/types/proto-es/v1/auth_service_pb.js
index 22f659a591..d5643a393f 100644
--- a/frontend/src/types/proto-es/v1/auth_service_pb.js
+++ b/frontend/src/types/proto-es/v1/auth_service_pb.js
@@ -12,7 +12,7 @@ import { file_v1_user_service } from "./user_service_pb";
* Describes the file v1/auth_service.proto.
*/
export const file_v1_auth_service = /*@__PURE__*/
- fileDesc("ChV2MS9hdXRoX3NlcnZpY2UucHJvdG8SC2J5dGViYXNlLnYxIosCCgxMb2dpblJlcXVlc3QSDQoFZW1haWwYASABKAkSEAoIcGFzc3dvcmQYAiABKAkSCwoDd2ViGAMgASgIEhAKCGlkcF9uYW1lGAQgASgJEjkKC2lkcF9jb250ZXh0GAUgASgLMiQuYnl0ZWJhc2UudjEuSWRlbnRpdHlQcm92aWRlckNvbnRleHQSFQoIb3RwX2NvZGUYBiABKAlIAIgBARIaCg1yZWNvdmVyeV9jb2RlGAcgASgJSAGIAQESGwoObWZhX3RlbXBfdG9rZW4YCCABKAlIAogBAUILCglfb3RwX2NvZGVCEAoOX3JlY292ZXJ5X2NvZGVCEQoPX21mYV90ZW1wX3Rva2VuIqwBChdJZGVudGl0eVByb3ZpZGVyQ29udGV4dBJECg5vYXV0aDJfY29udGV4dBgBIAEoCzIqLmJ5dGViYXNlLnYxLk9BdXRoMklkZW50aXR5UHJvdmlkZXJDb250ZXh0SAASQAoMb2lkY19jb250ZXh0GAIgASgLMiguYnl0ZWJhc2UudjEuT0lEQ0lkZW50aXR5UHJvdmlkZXJDb250ZXh0SABCCQoHY29udGV4dCItCh1PQXV0aDJJZGVudGl0eVByb3ZpZGVyQ29udGV4dBIMCgRjb2RlGAEgASgJIh0KG09JRENJZGVudGl0eVByb3ZpZGVyQ29udGV4dCKPAQoNTG9naW5SZXNwb25zZRINCgV0b2tlbhgBIAEoCRIbCg5tZmFfdGVtcF90b2tlbhgCIAEoCUgAiAEBEh4KFnJlcXVpcmVfcmVzZXRfcGFzc3dvcmQYAyABKAgSHwoEdXNlchgEIAEoCzIRLmJ5dGViYXNlLnYxLlVzZXJCEQoPX21mYV90ZW1wX3Rva2VuIg8KDUxvZ291dFJlcXVlc3Qy0gEKC0F1dGhTZXJ2aWNlEmEKBUxvZ2luEhkuYnl0ZWJhc2UudjEuTG9naW5SZXF1ZXN0GhouYnl0ZWJhc2UudjEuTG9naW5SZXNwb25zZSIhgOowAZjqMAGC0+STAhM6ASoiDi92MS9hdXRoL2xvZ2luEmAKBkxvZ291dBIaLmJ5dGViYXNlLnYxLkxvZ291dFJlcXVlc3QaFi5nb29nbGUucHJvdG9idWYuRW1wdHkiIoDqMAGY6jABgtPkkwIUOgEqIg8vdjEvYXV0aC9sb2dvdXRCpgEKD2NvbS5ieXRlYmFzZS52MUIQQXV0aFNlcnZpY2VQcm90b1ABWjRnaXRodWIuY29tL2J5dGViYXNlL2J5dGViYXNlL2JhY2tlbmQvZ2VuZXJhdGVkLWdvL3YxogIDQlhYqgILQnl0ZWJhc2UuVjHKAgtCeXRlYmFzZVxWMeICF0J5dGViYXNlXFYxXEdQQk1ldGFkYXRh6gIMQnl0ZWJhc2U6OlYxYgZwcm90bzM", [file_google_api_annotations, file_google_protobuf_empty, file_v1_annotation, file_v1_user_service]);
+ fileDesc("ChV2MS9hdXRoX3NlcnZpY2UucHJvdG8SC2J5dGViYXNlLnYxIosCCgxMb2dpblJlcXVlc3QSDQoFZW1haWwYASABKAkSEAoIcGFzc3dvcmQYAiABKAkSCwoDd2ViGAMgASgIEhAKCGlkcF9uYW1lGAQgASgJEjkKC2lkcF9jb250ZXh0GAUgASgLMiQuYnl0ZWJhc2UudjEuSWRlbnRpdHlQcm92aWRlckNvbnRleHQSFQoIb3RwX2NvZGUYBiABKAlIAIgBARIaCg1yZWNvdmVyeV9jb2RlGAcgASgJSAGIAQESGwoObWZhX3RlbXBfdG9rZW4YCCABKAlIAogBAUILCglfb3RwX2NvZGVCEAoOX3JlY292ZXJ5X2NvZGVCEQoPX21mYV90ZW1wX3Rva2VuIqwBChdJZGVudGl0eVByb3ZpZGVyQ29udGV4dBJECg5vYXV0aDJfY29udGV4dBgBIAEoCzIqLmJ5dGViYXNlLnYxLk9BdXRoMklkZW50aXR5UHJvdmlkZXJDb250ZXh0SAASQAoMb2lkY19jb250ZXh0GAIgASgLMiguYnl0ZWJhc2UudjEuT0lEQ0lkZW50aXR5UHJvdmlkZXJDb250ZXh0SABCCQoHY29udGV4dCItCh1PQXV0aDJJZGVudGl0eVByb3ZpZGVyQ29udGV4dBIMCgRjb2RlGAEgASgJIisKG09JRENJZGVudGl0eVByb3ZpZGVyQ29udGV4dBIMCgRjb2RlGAEgASgJIo8BCg1Mb2dpblJlc3BvbnNlEg0KBXRva2VuGAEgASgJEhsKDm1mYV90ZW1wX3Rva2VuGAIgASgJSACIAQESHgoWcmVxdWlyZV9yZXNldF9wYXNzd29yZBgDIAEoCBIfCgR1c2VyGAQgASgLMhEuYnl0ZWJhc2UudjEuVXNlckIRCg9fbWZhX3RlbXBfdG9rZW4iDwoNTG9nb3V0UmVxdWVzdDLSAQoLQXV0aFNlcnZpY2USYQoFTG9naW4SGS5ieXRlYmFzZS52MS5Mb2dpblJlcXVlc3QaGi5ieXRlYmFzZS52MS5Mb2dpblJlc3BvbnNlIiGA6jABmOowAYLT5JMCEzoBKiIOL3YxL2F1dGgvbG9naW4SYAoGTG9nb3V0EhouYnl0ZWJhc2UudjEuTG9nb3V0UmVxdWVzdBoWLmdvb2dsZS5wcm90b2J1Zi5FbXB0eSIigOowAZjqMAGC0+STAhQ6ASoiDy92MS9hdXRoL2xvZ291dEKmAQoPY29tLmJ5dGViYXNlLnYxQhBBdXRoU2VydmljZVByb3RvUAFaNGdpdGh1Yi5jb20vYnl0ZWJhc2UvYnl0ZWJhc2UvYmFja2VuZC9nZW5lcmF0ZWQtZ28vdjGiAgNCWFiqAgtCeXRlYmFzZS5WMcoCC0J5dGViYXNlXFYx4gIXQnl0ZWJhc2VcVjFcR1BCTWV0YWRhdGHqAgxCeXRlYmFzZTo6VjFiBnByb3RvMw", [file_google_api_annotations, file_google_protobuf_empty, file_v1_annotation, file_v1_user_service]);
/**
* Describes the message bytebase.v1.LoginRequest.
diff --git a/frontend/src/utils/auth.ts b/frontend/src/utils/auth.ts
index 513a3709ee..4930bb4184 100644
--- a/frontend/src/utils/auth.ts
+++ b/frontend/src/utils/auth.ts
@@ -1,4 +1,5 @@
import {
+ AUTH_IDP_INIT_MODULE,
AUTH_MFA_MODULE,
AUTH_OAUTH_CALLBACK_MODULE,
AUTH_OIDC_CALLBACK_MODULE,
@@ -19,5 +20,6 @@ export const isAuthRelatedRoute = (routeName: string) => {
AUTH_PASSWORD_FORGOT_MODULE,
AUTH_OAUTH_CALLBACK_MODULE,
AUTH_OIDC_CALLBACK_MODULE,
+ AUTH_IDP_INIT_MODULE,
].includes(routeName);
};
diff --git a/frontend/src/utils/sso.ts b/frontend/src/utils/sso.ts
index d5cba10ca6..5a7db1131d 100644
--- a/frontend/src/utils/sso.ts
+++ b/frontend/src/utils/sso.ts
@@ -1,9 +1,10 @@
-import { stringify } from "qs";
import type { OAuthState } from "@/types";
import type { IdentityProvider } from "@/types/proto-es/v1/idp_service_pb";
import { IdentityProviderType } from "@/types/proto-es/v1/idp_service_pb";
export const SSOConfigSessionKey = "sso-config";
+const OAUTH_STATE_PREFIX = "oauth_state_";
+const OAUTH_STATE_TTL = 10 * 60 * 1000; // 10 minutes in milliseconds
/**
* Validates that a URL is a safe HTTP/HTTPS URL to prevent XSS attacks.
@@ -18,22 +19,103 @@ function isValidHttpUrl(url: string): boolean {
}
}
+/**
+ * Generates a cryptographically secure random token for OAuth state parameter.
+ * Uses Web Crypto API to generate 32 bytes of random data.
+ * Returns base64url-encoded string for URL safety.
+ */
+function generateSecureToken(): string {
+ const array = new Uint8Array(32);
+ crypto.getRandomValues(array);
+ // Convert to base64url encoding (URL-safe, no padding)
+ return btoa(String.fromCharCode(...array))
+ .replace(/\+/g, "-")
+ .replace(/\//g, "_")
+ .replace(/=/g, "");
+}
+
+/**
+ * Stores OAuth state in localStorage with a prefixed key.
+ * The state includes security token, routing info, and timestamp.
+ */
+function storeOAuthState(state: OAuthState): void {
+ const key = `${OAUTH_STATE_PREFIX}${state.token}`;
+ try {
+ localStorage.setItem(key, JSON.stringify(state));
+ } catch (error) {
+ console.error("Failed to store OAuth state:", error);
+ throw new Error("Failed to store authentication state");
+ }
+}
+
+/**
+ * Retrieves and validates OAuth state from localStorage.
+ * Returns the state if valid, or null if missing/invalid/expired.
+ */
+export function retrieveOAuthState(token: string): OAuthState | null {
+ const key = `${OAUTH_STATE_PREFIX}${token}`;
+ try {
+ const stored = localStorage.getItem(key);
+ if (!stored) {
+ return null;
+ }
+ const state = JSON.parse(stored) as OAuthState;
+
+ // Validate timestamp (must be within TTL)
+ const now = Date.now();
+ if (now - state.timestamp > OAUTH_STATE_TTL) {
+ localStorage.removeItem(key);
+ return null;
+ }
+
+ return state;
+ } catch (error) {
+ console.error("Failed to retrieve OAuth state:", error);
+ return null;
+ }
+}
+
+/**
+ * Clears OAuth state from localStorage after use.
+ * This ensures single-use tokens for security.
+ */
+export function clearOAuthState(token: string): void {
+ const key = `${OAUTH_STATE_PREFIX}${token}`;
+ try {
+ localStorage.removeItem(key);
+ } catch (error) {
+ console.error("Failed to clear OAuth state:", error);
+ }
+}
+
export async function openWindowForSSO(
identityProvider: IdentityProvider,
popup = true,
- redirect = ""
+ redirect?: string
) {
+ // Generate cryptographically secure random token for CSRF protection
+ const token = generateSecureToken();
+
const state: OAuthState = {
+ token,
// we use type to determine oauth type when receiving the callback
event: `bb.oauth.signin.${identityProvider.name}`,
popup,
redirect,
+ timestamp: Date.now(),
+ // Store IdP type to determine correct context type in callback
+ idpType: identityProvider.type,
};
+ // Store state in localStorage before redirecting
+ storeOAuthState(state);
+
const uri = {
basePath: "",
query: {
- state: stringify(state),
+ // Only send the opaque token as per RFC 6749 and Auth0 best practices
+ // All other state data is stored server-side for security
+ state: token,
response_type: "code",
} as Record<string, string>,
};
diff --git a/frontend/src/views/IdPInitiatedSSO.vue b/frontend/src/views/IdPInitiatedSSO.vue
new file mode 100644
index 0000000000..b275de224c
--- /dev/null
+++ b/frontend/src/views/IdPInitiatedSSO.vue
@@ -0,0 +1,77 @@
+<template>
+ <div class="flex items-center justify-center min-h-screen">
+ <div class="text-center">
+ <BBSpin class="w-12 h-12 mx-auto" />
+ <h2 class="mt-4 text-xl font-semibold text-main">{{ message }}</h2>
+ <p v-if="errorMessage" class="mt-2 text-red-600">{{ errorMessage }}</p>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { onMounted, ref } from "vue";
+import { useRoute, useRouter } from "vue-router";
+import { BBSpin } from "@/bbkit";
+import { AUTH_SIGNIN_MODULE } from "@/router/auth";
+import { useIdentityProviderStore } from "@/store";
+import { openWindowForSSO } from "@/utils/sso";
+
+const route = useRoute();
+const router = useRouter();
+const idpStore = useIdentityProviderStore();
+
+const message = ref("Initializing secure login...");
+const errorMessage = ref("");
+
+onMounted(async () => {
+ try {
+ const idpSlug = route.query.idp;
+ const relayState = route.query.relay_state;
+
+ // Validate types - query params can be string, string[], or undefined
+ const idpSlugStr = typeof idpSlug === "string" ? idpSlug : undefined;
+ const relayStateStr =
+ typeof relayState === "string" ? relayState : undefined;
+
+ // Security: Validate relay_state
+ if (relayStateStr && !isValidRelayState(relayStateStr)) {
+ throw new Error("Invalid relay state parameter");
+ }
+
+ // Get IdP configuration
+ const idps = await idpStore.fetchIdentityProviderList();
+ const idp = idpSlugStr
+ ? await idpStore.getOrFetchIdentityProviderByName(`idps/${idpSlugStr}`)
+ : idps[0];
+
+ if (!idp) {
+ throw new Error("Identity provider not found");
+ }
+
+ message.value = `Logging in with ${idp.title}...`;
+
+ // Trigger OAuth redirect (same as SP-initiated flow)
+ // Pass relay_state if provided (for deep linking), otherwise undefined
+ // The auth store will handle undefined by using default redirect logic
+ await openWindowForSSO(idp, false, relayStateStr);
+ } catch (error) {
+ console.error("IdP-initiated SSO error:", error);
+ errorMessage.value =
+ error instanceof Error ? error.message : "Failed to initiate SSO";
+ message.value = "Authentication failed";
+
+ setTimeout(() => {
+ router.push({
+ name: AUTH_SIGNIN_MODULE,
+ query: { error: "sso_init_failed" },
+ });
+ }, 3000);
+ }
+});
+
+function isValidRelayState(state: string): boolean {
+ // Only allow relative URLs starting with /
+ // Reject protocol-relative URLs (//) to prevent open redirect attacks
+ return state.startsWith("/") && !state.startsWith("//");
+}
+</script>
diff --git a/frontend/src/views/OAuthCallback.vue b/frontend/src/views/OAuthCallback.vue
index 4ec8c00439..2cee3da686 100644
--- a/frontend/src/views/OAuthCallback.vue
+++ b/frontend/src/views/OAuthCallback.vue
@@ -15,12 +15,13 @@
<script lang="ts" setup>
import { create } from "@bufbuild/protobuf";
import { NButton } from "naive-ui";
-import { parse } from "qs";
import { onMounted, reactive } from "vue";
import { useRoute } from "vue-router";
import { AUTH_SIGNIN_MODULE } from "@/router/auth";
import { useAuthStore } from "@/store";
import { LoginRequestSchema } from "@/types/proto-es/v1/auth_service_pb";
+import { IdentityProviderType } from "@/types/proto-es/v1/idp_service_pb";
+import { retrieveOAuthState, clearOAuthState } from "@/utils/sso";
import type { OAuthState, OAuthWindowEventPayload } from "../types";
interface LocalState {
@@ -44,24 +45,55 @@ const state = reactive<LocalState>({
});
onMounted(() => {
- const queryState = parse((route.query.state as string) || "");
+ // State parameter is now an opaque token (RFC 6749 compliant)
+ const stateToken = route.query.state as string;
- if (queryState.event) {
- state.oAuthState = {
- event: queryState.event as string,
- popup: queryState.popup === "true" ? true : false,
- redirect: (queryState.redirect as string) || "",
- };
- state.hasError = false;
- state.message = "Successfully authorized. Redirecting back to Bytebase...";
- state.payload.code = (route.query.code as string) || "";
- } else {
+ // Validate state token exists
+ if (
+ !stateToken ||
+ typeof stateToken !== "string" ||
+ stateToken.length === 0
+ ) {
+ state.hasError = true;
+ state.message =
+ "Authentication failed: Invalid callback state. Please try again.";
+ state.oAuthState = undefined;
+ triggerAuthCallback();
+ return;
+ }
+
+ // Retrieve and validate stored state from localStorage using opaque token
+ const storedState = retrieveOAuthState(stateToken);
+
+ if (!storedState) {
+ state.hasError = true;
+ state.message =
+ "Authentication failed: Session expired or invalid. Please try again.";
+ state.oAuthState = undefined;
+ triggerAuthCallback();
+ return;
+ }
+
+ // Validate token matches (constant-time comparison via retrieval)
+ if (storedState.token !== stateToken) {
state.hasError = true;
state.message =
- "Failed to authorize. Invalid state passed to the oauth callback.";
+ "Authentication failed: Security validation failed. Please try again.";
state.oAuthState = undefined;
+ clearOAuthState(stateToken);
+ triggerAuthCallback();
+ return;
}
+ // State validation successful
+ state.oAuthState = storedState;
+ state.hasError = false;
+ state.message = "Successfully authorized. Redirecting back to Bytebase...";
+ state.payload.code = (route.query.code as string) || "";
+
+ // Clear state from localStorage (single-use token)
+ clearOAuthState(storedState.token);
+
triggerAuthCallback();
});
@@ -86,16 +118,27 @@ const triggerAuthCallback = async () => {
);
window.close();
} else {
+ // Determine context type based on the stored IdP type
+ // OIDC providers use oidcContext, OAuth2 providers use oauth2Context
+ const isOidc = oAuthState.idpType === IdentityProviderType.OIDC;
+
await authStore.login(
create(LoginRequestSchema, {
idpName: eventName.split(".").pop()!,
idpContext: {
- context: {
- case: "oauth2Context",
- value: {
- code: state.payload.code,
- },
- },
+ context: isOidc
+ ? {
+ case: "oidcContext",
+ value: {
+ code: state.payload.code,
+ },
+ }
+ : {
+ case: "oauth2Context",
+ value: {
+ code: state.payload.code,
+ },
+ },
},
web: true,
}),
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index 2ef91dfbd3..0e8933db9e 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -11746,7 +11746,10 @@ components:
description: OIDCIdentityProviderConfig is the structure for OIDC identity provider config.
OIDCIdentityProviderContext:
type: object
- properties: {}
+ properties:
+ code:
+ type: string
+ description: Authorization code from OIDC provider.
description: OpenID Connect authentication context.
ObjectSchema:
type: object
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 08ae75a91f..dda905f643 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -6204,6 +6204,11 @@ OAuth2 authentication context.
OpenID Connect authentication context.
+| Field | Type | Label | Description |
+| ----- | ---- | ----- | ----------- |
+| code | [string](#string) | | Authorization code from OIDC provider. |
+
+
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 225c4e12e0..53277415ee 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -17889,6 +17889,23 @@ Format: idps/{idp} </p></td>
<p>OpenID Connect authentication context.</p>
+ <table class="field-table">
+ <thead>
+ <tr><td>Field</td><td>Type</td><td>Label</td><td>Description</td></tr>
+ </thead>
+ <tbody>
+
+ <tr>
+ <td>code</td>
+ <td><a href="#string">string</a></td>
+ <td></td>
+ <td><p>Authorization code from OIDC provider. </p></td>
+ </tr>
+
+ </tbody>
+ </table>
+
+
diff --git a/proto/v1/v1/auth_service.proto b/proto/v1/v1/auth_service.proto
index a5b042079f..92f37eaf90 100644
--- a/proto/v1/v1/auth_service.proto
+++ b/proto/v1/v1/auth_service.proto
@@ -78,7 +78,10 @@ message OAuth2IdentityProviderContext {
}
// OpenID Connect authentication context.
-message OIDCIdentityProviderContext {}
+message OIDCIdentityProviderContext {
+ // Authorization code from OIDC provider.
+ string code = 1;
+}
message LoginResponse {
// Access token for authenticated requests.