forked from baron/baron-sso
Merge pull request 'SSO 로그인 방식을 팝업 기반으로 변경' (#334) from feature/devfront-refactor into dev
Reviewed-on: baron/baron-sso#334
This commit is contained in:
@@ -1,12 +1,19 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useAuth } from "react-oidc-context";
|
import { useAuth } from "react-oidc-context";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { userManager } from "../../lib/auth";
|
||||||
|
|
||||||
export default function AuthCallbackPage() {
|
export default function AuthCallbackPage() {
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// 팝업으로 열린 경우 signinPopupCallback 처리
|
||||||
|
if (window.opener) {
|
||||||
|
userManager.signinPopupCallback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (auth.isAuthenticated) {
|
if (auth.isAuthenticated) {
|
||||||
navigate("/", { replace: true });
|
navigate("/", { replace: true });
|
||||||
} else if (auth.error) {
|
} else if (auth.error) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ExternalLink, LogIn, ShieldHalf } from "lucide-react";
|
import { ExternalLink, LogIn, ShieldHalf } from "lucide-react";
|
||||||
import { useAuth } from "react-oidc-context";
|
import { useAuth } from "react-oidc-context";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
@@ -11,10 +12,15 @@ import {
|
|||||||
|
|
||||||
function LoginPage() {
|
function LoginPage() {
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const handleSSOLogin = () => {
|
const handleSSOLogin = async () => {
|
||||||
// OIDC client-side authentication flow started here
|
try {
|
||||||
auth.signinRedirect();
|
await auth.signinPopup();
|
||||||
|
navigate("/clients", { replace: true });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Popup login failed", error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -30,8 +30,9 @@ apiClient.interceptors.response.use(
|
|||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
// 401 발생 시 로그인 페이지로 리다이렉트
|
// 401 발생 시 로그인 페이지로 리다이렉트
|
||||||
const isAuthPath = window.location.pathname.startsWith("/callback");
|
const isAuthPath = window.location.pathname.startsWith("/callback");
|
||||||
if (!isAuthPath) {
|
const isLoginPath = window.location.pathname === "/login";
|
||||||
userManager.signinRedirect();
|
if (!isAuthPath && !isLoginPath) {
|
||||||
|
window.location.href = "/login";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export const oidcConfig: AuthProviderProps = {
|
|||||||
response_type: "code",
|
response_type: "code",
|
||||||
scope: "openid offline_access profile email", // offline_access for refresh token
|
scope: "openid offline_access profile email", // offline_access for refresh token
|
||||||
post_logout_redirect_uri: window.location.origin,
|
post_logout_redirect_uri: window.location.origin,
|
||||||
|
popup_redirect_uri: `${window.location.origin}/auth/callback`,
|
||||||
userStore: new WebStorageStateStore({ store: window.localStorage }),
|
userStore: new WebStorageStateStore({ store: window.localStorage }),
|
||||||
automaticSilentRenew: true,
|
automaticSilentRenew: true,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user