feat: add OIDC login via Microsoft Entra ID
This commit is contained in:
1 parent
9b4e1f9193
commit
58bead0e80
18 files changed
+586
-17
No files matched your search
@@ -1,8 +1,8 @@
|
||||
# Azure AD Configuration
|
||||
VITE_AZURE_CLIENT_ID=d182d8e3-fa47-4b93-a736-8c4b7c25bc97
|
||||
VITE_AZURE_AUTHORITY=https://login.microsoftonline.com/common/oauth2/v2.0/authorize
|
||||
VITE_AZURE_AUTHORITY=https://login.microsoftonline.com/5ef88004-e953-4b04-93db-64bbf49c6863/oauth2/v2.0/authorize
|
||||
VITE_AZURE_REDIRECT_URI=http://localhost:5173
|
||||
VITE_AZURE_POST_LOGOUT_REDIRECT_URI=http://localhost:5173
|
||||
|
||||
# API Configuration
|
||||
VITE_API_BASE_URL=https://wiki.dahyeon.us/v1
|
||||
VITE_API_BASE_URL=https://wiki.dahyeon.us
|
||||
@@ -0,0 +1,4 @@
|
||||
$ENDPOINT = "https://wiki.dahyeon.us/v1"
|
||||
# $ENDPOINT = "https://dev.dahyeon.us/v1"
|
||||
|
||||
kiota generate --openapi $ENDPOINT/api-yaml --language Typescript --output ./src/kiota --clean-output
|
||||
Generated
+90
@@ -18,6 +18,12 @@
|
||||
"@lexical/selection": "^0.38.2",
|
||||
"@lexical/table": "^0.38.2",
|
||||
"@lexical/utils": "^0.38.2",
|
||||
"@microsoft/kiota-abstractions": "^1.0.0-preview.99",
|
||||
"@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.99",
|
||||
"@microsoft/kiota-serialization-form": "^1.0.0-preview.99",
|
||||
"@microsoft/kiota-serialization-json": "^1.0.0-preview.99",
|
||||
"@microsoft/kiota-serialization-multipart": "^1.0.0-preview.99",
|
||||
"@microsoft/kiota-serialization-text": "^1.0.0-preview.99",
|
||||
"@radix-ui/react-alert-dialog": "^1.1.15",
|
||||
"@radix-ui/react-dialog": "^1.1.15",
|
||||
"@radix-ui/react-icons": "^1.3.2",
|
||||
@@ -1419,6 +1425,69 @@
|
||||
"yjs": ">=13.5.22"
|
||||
}
|
||||
},
|
||||
"node_modules/@microsoft/kiota-abstractions": {
|
||||
"version": "1.0.0-preview.99",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/kiota-abstractions/-/kiota-abstractions-1.0.0-preview.99.tgz",
|
||||
"integrity": "sha512-6qrlwGCO3DbvpA7tszqk7JNQPFPDg8gv5NGMTziwdtHqaQrUALKusm3vdJGPVGrbNiZL6/lBaY5NSUvLtlhRCg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@opentelemetry/api": "^1.7.0",
|
||||
"@std-uritemplate/std-uritemplate": "^2.0.0",
|
||||
"tinyduration": "^3.3.0",
|
||||
"tslib": "^2.6.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@microsoft/kiota-http-fetchlibrary": {
|
||||
"version": "1.0.0-preview.99",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/kiota-http-fetchlibrary/-/kiota-http-fetchlibrary-1.0.0-preview.99.tgz",
|
||||
"integrity": "sha512-lIruiYf8L7DPG0Fm92QN5YK4zx4sh76EtTONUAqBCxt5AtEJ7KQceBajaXQsjfcndUAp9LmDVdqR44o8sc9/mA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@microsoft/kiota-abstractions": "^1.0.0-preview.99",
|
||||
"@opentelemetry/api": "^1.7.0",
|
||||
"tslib": "^2.6.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@microsoft/kiota-serialization-form": {
|
||||
"version": "1.0.0-preview.99",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/kiota-serialization-form/-/kiota-serialization-form-1.0.0-preview.99.tgz",
|
||||
"integrity": "sha512-BdXxqNfy+5yWTyxpBguqJYy6E9RRotrDClRcUO89okFcR5N6s6xenjsvGw++q9KWNi7qcHrqaG8xlRz1TLk81Q==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@microsoft/kiota-abstractions": "^1.0.0-preview.99",
|
||||
"tslib": "^2.6.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@microsoft/kiota-serialization-json": {
|
||||
"version": "1.0.0-preview.99",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/kiota-serialization-json/-/kiota-serialization-json-1.0.0-preview.99.tgz",
|
||||
"integrity": "sha512-kDmMYmB7XkRprlLviEynRPDkE45JDxqiuUopfBRMvNK4qhzFiJTXGLihZ2FG6fdVu9LbV3/W0QxbeGP35kDK6A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@microsoft/kiota-abstractions": "^1.0.0-preview.99",
|
||||
"tslib": "^2.6.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@microsoft/kiota-serialization-multipart": {
|
||||
"version": "1.0.0-preview.99",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/kiota-serialization-multipart/-/kiota-serialization-multipart-1.0.0-preview.99.tgz",
|
||||
"integrity": "sha512-cfviCAVTlZPD+MUgdTIgsX/IfHND+gKQhem3vJeo7l5Qqz2rvvVFXOHwECI19umO9Un1QFKe1V5wg+M+aj90+g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@microsoft/kiota-abstractions": "^1.0.0-preview.99",
|
||||
"tslib": "^2.6.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@microsoft/kiota-serialization-text": {
|
||||
"version": "1.0.0-preview.99",
|
||||
"resolved": "https://registry.npmjs.org/@microsoft/kiota-serialization-text/-/kiota-serialization-text-1.0.0-preview.99.tgz",
|
||||
"integrity": "sha512-gcBffQRI1soHVAiS4YjfMr3SQ9fC8xVUGMfarTTszU4PjpxyFOknaWoFdt/0rvMeavI9jOtbyvDKAf77cZyYIQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@microsoft/kiota-abstractions": "^1.0.0-preview.99",
|
||||
"tslib": "^2.6.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@nodelib/fs.scandir": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
||||
@@ -1457,6 +1526,15 @@
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/@opentelemetry/api": {
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz",
|
||||
"integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=8.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@preact/signals-core": {
|
||||
"version": "1.12.1",
|
||||
"resolved": "https://registry.npmjs.org/@preact/signals-core/-/signals-core-1.12.1.tgz",
|
||||
@@ -2214,6 +2292,12 @@
|
||||
"win32"
|
||||
]
|
||||
},
|
||||
"node_modules/@std-uritemplate/std-uritemplate": {
|
||||
"version": "2.0.8",
|
||||
"resolved": "https://registry.npmjs.org/@std-uritemplate/std-uritemplate/-/std-uritemplate-2.0.8.tgz",
|
||||
"integrity": "sha512-8oj7jKksoTRxjdPkWKX9FyOKDS8ORBm+ZfTSHm0f3eYha8cI0O1d57gyduOIAX7Y2uUukNDNlxlvGb+FFkE7yQ==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@tailwindcss/node": {
|
||||
"version": "4.1.16",
|
||||
"resolved": "https://registry.npmjs.org/@tailwindcss/node/-/node-4.1.16.tgz",
|
||||
@@ -4886,6 +4970,12 @@
|
||||
"url": "https://opencollective.com/webpack"
|
||||
}
|
||||
},
|
||||
"node_modules/tinyduration": {
|
||||
"version": "3.4.1",
|
||||
"resolved": "https://registry.npmjs.org/tinyduration/-/tinyduration-3.4.1.tgz",
|
||||
"integrity": "sha512-NemFoamVYn7TmtwZKZ3OiliM9fZkr6EWiTM+wKknco6POSy2gS689xx/pXip0JYp40HXpUw6k65CUYHWYUXdaA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tinyglobby": {
|
||||
"version": "0.2.15",
|
||||
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz",
|
||||
|
||||
@@ -20,6 +20,12 @@
|
||||
"@lexical/selection": "^0.38.2",
|
||||
"@lexical/table": "^0.38.2",
|
||||
"@lexical/utils": "^0.38.2",
|
||||
"@microsoft/kiota-abstractions": "^1.0.0-preview.99",
|
||||
"@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.99",
|
||||
"@microsoft/kiota-serialization-form": "^1.0.0-preview.99",
|
||||
"@microsoft/kiota-serialization-json": "^1.0.0-preview.99",
|
||||
"@microsoft/kiota-serialization-multipart": "^1.0.0-preview.99",
|
||||
"@microsoft/kiota-serialization-text": "^1.0.0-preview.99",
|
||||
"@radix-ui/react-alert-dialog": "^1.1.15",
|
||||
"@radix-ui/react-dialog": "^1.1.15",
|
||||
"@radix-ui/react-icons": "^1.3.2",
|
||||
|
||||
+2
-1
@@ -3,7 +3,7 @@ import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
||||
import { MsalProvider } from '@azure/msal-react';
|
||||
import { PublicClientApplication } from '@azure/msal-browser';
|
||||
import { msalConfig } from '../config/authConfig';
|
||||
import { PageListPage, PageDetailPage, PageEditPage } from '../pages';
|
||||
import { PageListPage, PageDetailPage, PageEditPage, TestApiPage } from '../pages';
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
@@ -27,6 +27,7 @@ function App() {
|
||||
<Route path="/pages/new" element={<PageEditPage />} />
|
||||
<Route path="/pages/:id" element={<PageDetailPage />} />
|
||||
<Route path="/pages/:id/edit" element={<PageEditPage />} />
|
||||
<Route path="/test-api" element={<TestApiPage />} />
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
</QueryClientProvider>
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import { FetchRequestAdapter } from '@microsoft/kiota-http-fetchlibrary';
|
||||
import { createApiClient } from '../kiota/apiClient';
|
||||
import type { IPublicClientApplication } from '@azure/msal-browser';
|
||||
import type { AuthenticationProvider, RequestInformation } from '@microsoft/kiota-abstractions';
|
||||
|
||||
/**
|
||||
* MSAL 기반 AuthenticationProvider
|
||||
*/
|
||||
class MsalAuthenticationProvider implements AuthenticationProvider {
|
||||
private msalInstance: IPublicClientApplication;
|
||||
|
||||
constructor(msalInstance: IPublicClientApplication) {
|
||||
this.msalInstance = msalInstance;
|
||||
}
|
||||
|
||||
async authenticateRequest(request: RequestInformation): Promise<void> {
|
||||
const accounts = this.msalInstance.getAllAccounts();
|
||||
|
||||
if (accounts.length === 0) {
|
||||
throw new Error('No authenticated account found. Please login first.');
|
||||
}
|
||||
|
||||
try {
|
||||
// ID Token 사용 (백엔드가 사용자 인증만 확인하는 경우)
|
||||
const account = accounts[0];
|
||||
|
||||
// ID Token이 없거나 만료된 경우 새로 획득
|
||||
const response = await this.msalInstance.acquireTokenSilent({
|
||||
scopes: ['openid', 'profile'],
|
||||
account: account,
|
||||
});
|
||||
|
||||
// Authorization 헤더에 ID Token 추가
|
||||
const idToken = response.idToken;
|
||||
request.headers.add('Authorization', `Bearer ${idToken}`);
|
||||
} catch (error) {
|
||||
console.error('Token acquisition failed:', error);
|
||||
throw new Error('Failed to acquire ID token');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 인증이 포함된 API 클라이언트 생성
|
||||
*/
|
||||
export function createAuthenticatedApiClient(msalInstance: IPublicClientApplication) {
|
||||
const baseUrl = import.meta.env.VITE_API_BASE_URL || 'https://wiki.dahyeon.us/v1';
|
||||
|
||||
const authProvider = new MsalAuthenticationProvider(msalInstance);
|
||||
const requestAdapter = new FetchRequestAdapter(authProvider);
|
||||
requestAdapter.baseUrl = baseUrl;
|
||||
|
||||
return createApiClient(requestAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 인증 없는 API 클라이언트 생성 (public endpoints용)
|
||||
*/
|
||||
export function createPublicApiClient() {
|
||||
const baseUrl = import.meta.env.VITE_API_BASE_URL || 'https://wiki.dahyeon.us/v1';
|
||||
|
||||
const requestAdapter = new FetchRequestAdapter();
|
||||
requestAdapter.baseUrl = baseUrl;
|
||||
|
||||
return createApiClient(requestAdapter);
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { LogLevel } from '@azure/msal-browser';
|
||||
import type { Configuration } from '@azure/msal-browser';
|
||||
import { LogLevel, type Configuration, type RedirectRequest } from '@azure/msal-browser';
|
||||
|
||||
/**
|
||||
* Configuration object to be passed to MSAL instance on creation.
|
||||
@@ -48,13 +47,21 @@ export const msalConfig: Configuration = {
|
||||
* For more information about OIDC scopes, visit:
|
||||
* https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-permissions-and-consent#openid-connect-scopes
|
||||
*/
|
||||
export const loginRequest = {
|
||||
export const loginRequest: RedirectRequest = {
|
||||
scopes: ['User.Read'], // Microsoft Graph API에서 사용자 프로필 읽기
|
||||
authority: import.meta.env.VITE_AZURE_AUTHORITY || '',
|
||||
};
|
||||
|
||||
/**
|
||||
* API 호출을 위한 스코프
|
||||
* API 호출을 위한 스코프 (백엔드 API 접근)
|
||||
*
|
||||
* 주의: 이 스코프를 사용하려면 Azure Portal에서 다음 설정이 필요합니다:
|
||||
* 1. App Registration > Expose an API > Add a scope
|
||||
* 2. App Registration > API permissions > Add permission > My APIs > 위에서 만든 API 선택
|
||||
* 3. Admin consent 승인
|
||||
*
|
||||
* 현재는 ID Token을 사용하므로 이 설정은 사용하지 않습니다.
|
||||
*/
|
||||
export const apiRequest = {
|
||||
scopes: [`api://${import.meta.env.VITE_AZURE_CLIENT_ID}/.default`],
|
||||
};
|
||||
// export const apiRequest: RedirectRequest = {
|
||||
// scopes: [`api://${import.meta.env.VITE_AZURE_CLIENT_ID}/.default`],
|
||||
// };
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
body {
|
||||
@apply min-h-screen bg-[#1e1e1e] text-[#e4e4e4];
|
||||
font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
font-family: "Asta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
}
|
||||
|
||||
/* Lexical 에디터와 뷰어에서 인라인 스타일 허용 */
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// Generated by Microsoft Kiota
|
||||
// @ts-ignore
|
||||
import { type V1RequestBuilder, V1RequestBuilderNavigationMetadata, V1RequestBuilderRequestsMetadata } from './v1/index.js';
|
||||
// @ts-ignore
|
||||
import { apiClientProxifier, ParseNodeFactoryRegistry, SerializationWriterFactoryRegistry, type BaseRequestBuilder, type KeysToExcludeForNavigationMetadata, type NavigationMetadata, type RequestAdapter } from '@microsoft/kiota-abstractions';
|
||||
// @ts-ignore
|
||||
import { FormParseNodeFactory, FormSerializationWriterFactory } from '@microsoft/kiota-serialization-form';
|
||||
// @ts-ignore
|
||||
import { JsonParseNodeFactory, JsonSerializationWriterFactory } from '@microsoft/kiota-serialization-json';
|
||||
// @ts-ignore
|
||||
import { MultipartSerializationWriterFactory } from '@microsoft/kiota-serialization-multipart';
|
||||
// @ts-ignore
|
||||
import { TextParseNodeFactory, TextSerializationWriterFactory } from '@microsoft/kiota-serialization-text';
|
||||
|
||||
/**
|
||||
* The main entry point of the SDK, exposes the configuration and the fluent API.
|
||||
*/
|
||||
export interface ApiClient extends BaseRequestBuilder<ApiClient> {
|
||||
/**
|
||||
* The v1 property
|
||||
*/
|
||||
get v1(): V1RequestBuilder;
|
||||
}
|
||||
/**
|
||||
* Instantiates a new {@link ApiClient} and sets the default values.
|
||||
* @param requestAdapter The request adapter to use to execute the requests.
|
||||
*/
|
||||
// @ts-ignore
|
||||
export function createApiClient(requestAdapter: RequestAdapter) {
|
||||
if (requestAdapter === undefined) {
|
||||
throw new Error("requestAdapter cannot be undefined");
|
||||
}
|
||||
const serializationWriterFactory = requestAdapter.getSerializationWriterFactory() as SerializationWriterFactoryRegistry;
|
||||
const parseNodeFactoryRegistry = requestAdapter.getParseNodeFactory() as ParseNodeFactoryRegistry;
|
||||
const backingStoreFactory = requestAdapter.getBackingStoreFactory();
|
||||
|
||||
if (parseNodeFactoryRegistry.registerDefaultDeserializer) {
|
||||
parseNodeFactoryRegistry.registerDefaultDeserializer(JsonParseNodeFactory, backingStoreFactory);
|
||||
parseNodeFactoryRegistry.registerDefaultDeserializer(TextParseNodeFactory, backingStoreFactory);
|
||||
parseNodeFactoryRegistry.registerDefaultDeserializer(FormParseNodeFactory, backingStoreFactory);
|
||||
}
|
||||
|
||||
if (serializationWriterFactory.registerDefaultSerializer) {
|
||||
serializationWriterFactory.registerDefaultSerializer(JsonSerializationWriterFactory);
|
||||
serializationWriterFactory.registerDefaultSerializer(TextSerializationWriterFactory);
|
||||
serializationWriterFactory.registerDefaultSerializer(FormSerializationWriterFactory);
|
||||
serializationWriterFactory.registerDefaultSerializer(MultipartSerializationWriterFactory);
|
||||
}
|
||||
|
||||
if (requestAdapter.baseUrl === undefined || requestAdapter.baseUrl === null || requestAdapter.baseUrl === "") {
|
||||
requestAdapter.baseUrl = "https:/wiki.dahyeon.us";
|
||||
}
|
||||
const pathParameters: Record<string, unknown> = {
|
||||
"baseurl": requestAdapter.baseUrl,
|
||||
};
|
||||
return apiClientProxifier<ApiClient>(requestAdapter, pathParameters, ApiClientNavigationMetadata, undefined);
|
||||
}
|
||||
/**
|
||||
* Uri template for the request builder.
|
||||
*/
|
||||
export const ApiClientUriTemplate = "{+baseurl}";
|
||||
/**
|
||||
* Metadata for all the navigation properties in the request builder.
|
||||
*/
|
||||
export const ApiClientNavigationMetadata: Record<Exclude<keyof ApiClient, KeysToExcludeForNavigationMetadata>, NavigationMetadata> = {
|
||||
v1: {
|
||||
requestsMetadata: V1RequestBuilderRequestsMetadata,
|
||||
navigationMetadata: V1RequestBuilderNavigationMetadata,
|
||||
},
|
||||
};
|
||||
/* tslint:enable */
|
||||
/* eslint-enable */
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"descriptionHash": "200836B16636159389C7FE3249A16B5C32640105CCD00949343B15A4581D4C6E47D7AB178C27CFF8CCC82766AD8A69E3521D91360A4121A0EDB212B478B48B84",
|
||||
"descriptionLocation": "https://wiki.dahyeon.us/v1/api-yaml",
|
||||
"lockFileVersion": "1.0.0",
|
||||
"kiotaVersion": "1.28.0",
|
||||
"clientClassName": "ApiClient",
|
||||
"typeAccessModifier": "Public",
|
||||
"clientNamespaceName": "ApiSdk",
|
||||
"language": "TypeScript",
|
||||
"usesBackingStore": false,
|
||||
"excludeBackwardCompatible": false,
|
||||
"includeAdditionalData": true,
|
||||
"disableSSLValidation": false,
|
||||
"serializers": [
|
||||
"Microsoft.Kiota.Serialization.Json.JsonSerializationWriterFactory",
|
||||
"Microsoft.Kiota.Serialization.Text.TextSerializationWriterFactory",
|
||||
"Microsoft.Kiota.Serialization.Form.FormSerializationWriterFactory",
|
||||
"Microsoft.Kiota.Serialization.Multipart.MultipartSerializationWriterFactory"
|
||||
],
|
||||
"deserializers": [
|
||||
"Microsoft.Kiota.Serialization.Json.JsonParseNodeFactory",
|
||||
"Microsoft.Kiota.Serialization.Text.TextParseNodeFactory",
|
||||
"Microsoft.Kiota.Serialization.Form.FormParseNodeFactory"
|
||||
],
|
||||
"structuredMimeTypes": [
|
||||
"application/json",
|
||||
"text/plain;q=0.9",
|
||||
"application/x-www-form-urlencoded;q=0.2",
|
||||
"multipart/form-data;q=0.1"
|
||||
],
|
||||
"includePatterns": [],
|
||||
"excludePatterns": [],
|
||||
"disabledValidationRules": []
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// Generated by Microsoft Kiota
|
||||
|
||||
/* tslint:enable */
|
||||
/* eslint-enable */
|
||||
@@ -0,0 +1,52 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// Generated by Microsoft Kiota
|
||||
// @ts-ignore
|
||||
import { SigninRequestBuilderRequestsMetadata, type SigninRequestBuilder } from './signin/index.js';
|
||||
// @ts-ignore
|
||||
import { type BaseRequestBuilder, type KeysToExcludeForNavigationMetadata, type NavigationMetadata, type Parsable, type ParsableFactory, type RequestConfiguration, type RequestInformation, type RequestsMetadata } from '@microsoft/kiota-abstractions';
|
||||
|
||||
/**
|
||||
* Builds and executes requests for operations under /v1/account
|
||||
*/
|
||||
export interface AccountRequestBuilder extends BaseRequestBuilder<AccountRequestBuilder> {
|
||||
/**
|
||||
* The signin property
|
||||
*/
|
||||
get signin(): SigninRequestBuilder;
|
||||
/**
|
||||
* @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
|
||||
* @returns {Promise<ArrayBuffer>}
|
||||
*/
|
||||
get(requestConfiguration?: RequestConfiguration<object> | undefined) : Promise<ArrayBuffer | undefined>;
|
||||
/**
|
||||
* @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
|
||||
* @returns {RequestInformation}
|
||||
*/
|
||||
toGetRequestInformation(requestConfiguration?: RequestConfiguration<object> | undefined) : RequestInformation;
|
||||
}
|
||||
/**
|
||||
* Uri template for the request builder.
|
||||
*/
|
||||
export const AccountRequestBuilderUriTemplate = "{+baseurl}/v1/account";
|
||||
/**
|
||||
* Metadata for all the navigation properties in the request builder.
|
||||
*/
|
||||
export const AccountRequestBuilderNavigationMetadata: Record<Exclude<keyof AccountRequestBuilder, KeysToExcludeForNavigationMetadata>, NavigationMetadata> = {
|
||||
signin: {
|
||||
requestsMetadata: SigninRequestBuilderRequestsMetadata,
|
||||
},
|
||||
};
|
||||
/**
|
||||
* Metadata for all the requests in the request builder.
|
||||
*/
|
||||
export const AccountRequestBuilderRequestsMetadata: RequestsMetadata = {
|
||||
get: {
|
||||
uriTemplate: AccountRequestBuilderUriTemplate,
|
||||
responseBodyContentType: "application/json",
|
||||
adapterMethodName: "sendPrimitive",
|
||||
responseBodyFactory: "ArrayBuffer",
|
||||
},
|
||||
};
|
||||
/* tslint:enable */
|
||||
/* eslint-enable */
|
||||
@@ -0,0 +1,38 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// Generated by Microsoft Kiota
|
||||
// @ts-ignore
|
||||
import { type BaseRequestBuilder, type Parsable, type ParsableFactory, type RequestConfiguration, type RequestInformation, type RequestsMetadata } from '@microsoft/kiota-abstractions';
|
||||
|
||||
/**
|
||||
* Builds and executes requests for operations under /v1/account/signin
|
||||
*/
|
||||
export interface SigninRequestBuilder extends BaseRequestBuilder<SigninRequestBuilder> {
|
||||
/**
|
||||
* @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
|
||||
* @returns {Promise<ArrayBuffer>}
|
||||
*/
|
||||
get(requestConfiguration?: RequestConfiguration<object> | undefined) : Promise<ArrayBuffer | undefined>;
|
||||
/**
|
||||
* @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
|
||||
* @returns {RequestInformation}
|
||||
*/
|
||||
toGetRequestInformation(requestConfiguration?: RequestConfiguration<object> | undefined) : RequestInformation;
|
||||
}
|
||||
/**
|
||||
* Uri template for the request builder.
|
||||
*/
|
||||
export const SigninRequestBuilderUriTemplate = "{+baseurl}/v1/account/signin";
|
||||
/**
|
||||
* Metadata for all the requests in the request builder.
|
||||
*/
|
||||
export const SigninRequestBuilderRequestsMetadata: RequestsMetadata = {
|
||||
get: {
|
||||
uriTemplate: SigninRequestBuilderUriTemplate,
|
||||
responseBodyContentType: "application/json",
|
||||
adapterMethodName: "sendPrimitive",
|
||||
responseBodyFactory: "ArrayBuffer",
|
||||
},
|
||||
};
|
||||
/* tslint:enable */
|
||||
/* eslint-enable */
|
||||
@@ -0,0 +1,53 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// Generated by Microsoft Kiota
|
||||
// @ts-ignore
|
||||
import { AccountRequestBuilderNavigationMetadata, AccountRequestBuilderRequestsMetadata, type AccountRequestBuilder } from './account/index.js';
|
||||
// @ts-ignore
|
||||
import { type BaseRequestBuilder, type KeysToExcludeForNavigationMetadata, type NavigationMetadata, type Parsable, type ParsableFactory, type RequestConfiguration, type RequestInformation, type RequestsMetadata } from '@microsoft/kiota-abstractions';
|
||||
|
||||
/**
|
||||
* Builds and executes requests for operations under /v1
|
||||
*/
|
||||
export interface V1RequestBuilder extends BaseRequestBuilder<V1RequestBuilder> {
|
||||
/**
|
||||
* The account property
|
||||
*/
|
||||
get account(): AccountRequestBuilder;
|
||||
/**
|
||||
* @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
|
||||
* @returns {Promise<ArrayBuffer>}
|
||||
*/
|
||||
get(requestConfiguration?: RequestConfiguration<object> | undefined) : Promise<ArrayBuffer | undefined>;
|
||||
/**
|
||||
* @param requestConfiguration Configuration for the request such as headers, query parameters, and middleware options.
|
||||
* @returns {RequestInformation}
|
||||
*/
|
||||
toGetRequestInformation(requestConfiguration?: RequestConfiguration<object> | undefined) : RequestInformation;
|
||||
}
|
||||
/**
|
||||
* Uri template for the request builder.
|
||||
*/
|
||||
export const V1RequestBuilderUriTemplate = "{+baseurl}/v1";
|
||||
/**
|
||||
* Metadata for all the navigation properties in the request builder.
|
||||
*/
|
||||
export const V1RequestBuilderNavigationMetadata: Record<Exclude<keyof V1RequestBuilder, KeysToExcludeForNavigationMetadata>, NavigationMetadata> = {
|
||||
account: {
|
||||
requestsMetadata: AccountRequestBuilderRequestsMetadata,
|
||||
navigationMetadata: AccountRequestBuilderNavigationMetadata,
|
||||
},
|
||||
};
|
||||
/**
|
||||
* Metadata for all the requests in the request builder.
|
||||
*/
|
||||
export const V1RequestBuilderRequestsMetadata: RequestsMetadata = {
|
||||
get: {
|
||||
uriTemplate: V1RequestBuilderUriTemplate,
|
||||
responseBodyContentType: "application/json",
|
||||
adapterMethodName: "sendPrimitive",
|
||||
responseBodyFactory: "ArrayBuffer",
|
||||
},
|
||||
};
|
||||
/* tslint:enable */
|
||||
/* eslint-enable */
|
||||
@@ -0,0 +1,138 @@
|
||||
import { useState } from 'react';
|
||||
import { useMsal } from '@azure/msal-react';
|
||||
import { Layout } from '../shared/Layout';
|
||||
import { createAuthenticatedApiClient } from '../config/apiClientFactory';
|
||||
|
||||
export function TestApiPage() {
|
||||
const { instance, accounts } = useMsal();
|
||||
const [result, setResult] = useState<string>('');
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string>('');
|
||||
|
||||
const testAccountApi = async () => {
|
||||
if (accounts.length === 0) {
|
||||
setError('로그인이 필요합니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
setError('');
|
||||
setResult('');
|
||||
|
||||
try {
|
||||
const apiClient = createAuthenticatedApiClient(instance);
|
||||
|
||||
// GET /v1/account 호출
|
||||
const response = await apiClient.v1.account.get();
|
||||
|
||||
setResult(JSON.stringify(response, null, 2));
|
||||
} catch (err) {
|
||||
console.error('API call failed:', err);
|
||||
setError(err instanceof Error ? err.message : '알 수 없는 오류가 발생했습니다.');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const isAuthenticated = accounts.length > 0;
|
||||
|
||||
return (
|
||||
<Layout showSidebar={false}>
|
||||
<div className="max-w-4xl mx-auto">
|
||||
<h1 className="text-3xl font-bold text-[#e4e4e4] mb-6">API 테스트</h1>
|
||||
|
||||
<div className="bg-[#252526] border border-[#3e3e42] rounded-lg p-6 mb-6">
|
||||
<h2 className="text-xl font-semibold text-[#e4e4e4] mb-4">인증 상태</h2>
|
||||
{isAuthenticated ? (
|
||||
<div className="space-y-2">
|
||||
<p className="text-[#9d9d9d]">
|
||||
✅ 로그인됨: <span className="text-[#4db8ff]">{accounts[0]?.username}</span>
|
||||
</p>
|
||||
<p className="text-[#9d9d9d] text-sm">
|
||||
계정 ID: {accounts[0]?.homeAccountId}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-[#9d9d9d]">❌ 로그인되지 않음</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="bg-[#252526] border border-[#3e3e42] rounded-lg p-6 mb-6">
|
||||
<h2 className="text-xl font-semibold text-[#e4e4e4] mb-4">API 호출 테스트</h2>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<p className="text-[#9d9d9d] text-sm mb-2">
|
||||
엔드포인트: <code className="text-[#4db8ff]">GET https://wiki.dahyeon.us/v1/account</code>
|
||||
</p>
|
||||
<button
|
||||
onClick={testAccountApi}
|
||||
// disabled={!isAuthenticated || isLoading}
|
||||
className="px-4 py-2 bg-[#0078d4] hover:bg-[#106ebe] text-white rounded transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
{isLoading ? '호출 중...' : 'GET /account 호출'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="p-4 bg-red-900/20 border border-red-500/50 rounded">
|
||||
<p className="text-red-400 font-semibold mb-1">오류 발생</p>
|
||||
<p className="text-red-300 text-sm">{error}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{result && (
|
||||
<div className="space-y-2">
|
||||
<p className="text-[#e4e4e4] font-semibold">응답:</p>
|
||||
<pre className="bg-[#1e1e1e] border border-[#3e3e42] rounded p-4 overflow-x-auto text-sm text-[#e4e4e4]">
|
||||
{result}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-[#252526] border border-[#3e3e42] rounded-lg p-6">
|
||||
<h2 className="text-xl font-semibold text-[#e4e4e4] mb-4">설정 가이드</h2>
|
||||
<div className="space-y-3 text-sm text-[#9d9d9d]">
|
||||
<div>
|
||||
<p className="font-semibold text-[#e4e4e4] mb-2">1. Azure Portal 설정</p>
|
||||
<ul className="list-disc list-inside space-y-1 ml-4">
|
||||
<li>App Registration 생성</li>
|
||||
<li><strong>Redirect URIs</strong> 추가:
|
||||
<ul className="list-circle list-inside ml-6 mt-1">
|
||||
<li>개발: <code className="text-[#4db8ff]">http://localhost:5173</code></li>
|
||||
<li>프로덕션: <code className="text-[#4db8ff]">https://wiki.dahyeon.us</code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Platform: <code>Single-page application (SPA)</code></li>
|
||||
<li>API permissions에서 필요한 스코프 추가</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="font-semibold text-[#e4e4e4] mb-2">2. .env 파일 설정</p>
|
||||
<pre className="bg-[#1e1e1e] border border-[#3e3e42] rounded p-3 overflow-x-auto text-xs">
|
||||
{`VITE_AZURE_CLIENT_ID=your-client-id
|
||||
VITE_AZURE_AUTHORITY=https://login.microsoftonline.com/your-tenant-id
|
||||
VITE_AZURE_REDIRECT_URI=http://localhost:5173
|
||||
VITE_API_BASE_URL=https://wiki.dahyeon.us/v1`}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="font-semibold text-[#e4e4e4] mb-2">3. 인증 흐름</p>
|
||||
<ol className="list-decimal list-inside space-y-1 ml-4">
|
||||
<li>사용자가 "로그인" 버튼 클릭</li>
|
||||
<li>MSAL이 Azure AD 로그인 팝업 표시</li>
|
||||
<li>사용자 인증 후 리다이렉트 URI로 돌아옴</li>
|
||||
<li>MSAL이 토큰을 세션 스토리지에 저장</li>
|
||||
<li>API 호출 시 자동으로 Bearer 토큰 추가</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './PageListPage';
|
||||
export * from './PageDetailPage';
|
||||
export * from './PageEditPage';
|
||||
export * from './TestApiPage';
|
||||
@@ -10,26 +10,25 @@ export function AuthButton() {
|
||||
const handleLogin = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
await instance.loginPopup(loginRequest);
|
||||
await instance.loginRedirect(loginRequest);
|
||||
} catch (error) {
|
||||
console.error('Login failed:', error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
// loginRedirect는 페이지를 이동시키므로 finally 블록이 실행되지 않음
|
||||
};
|
||||
|
||||
const handleLogout = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
await instance.logoutPopup({
|
||||
await instance.logoutRedirect({
|
||||
postLogoutRedirectUri: '/',
|
||||
mainWindowRedirectUri: '/',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Logout failed:', error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
// logoutRedirect는 페이지를 이동시키므로 finally 블록이 실행되지 않음
|
||||
};
|
||||
|
||||
const isAuthenticated = accounts.length > 0;
|
||||
|
||||
@@ -45,7 +45,7 @@ export function Layout({ children, showSidebar = true, rightSidebar }: LayoutPro
|
||||
</button>
|
||||
)}
|
||||
<Link to="/" className="text-xl font-semibold text-[#e4e4e4] hover:text-[#4db8ff] transition-colors">
|
||||
Gem Wiki (잼위키)
|
||||
토머위키
|
||||
</Link>
|
||||
</div>
|
||||
<nav className="flex items-center gap-4 md:gap-6 text-sm">
|
||||
|
||||
Reference in new issue
Block a user