connectbase-client 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/connect-base.umd.js +2 -2
- package/dist/index.d.mts +50 -81
- package/dist/index.d.ts +50 -81
- package/dist/index.js +81 -102
- package/dist/index.mjs +81 -102
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1282,26 +1282,12 @@ interface EnabledProviderInfo {
|
|
|
1282
1282
|
interface EnabledProvidersResponse {
|
|
1283
1283
|
providers: EnabledProviderInfo[];
|
|
1284
1284
|
}
|
|
1285
|
-
/**
|
|
1286
|
-
* OAuth 인증 URL 요청
|
|
1287
|
-
*/
|
|
1288
|
-
interface GetAuthorizationURLRequest {
|
|
1289
|
-
redirect_uri: string;
|
|
1290
|
-
state?: string;
|
|
1291
|
-
}
|
|
1292
1285
|
/**
|
|
1293
1286
|
* OAuth 인증 URL 응답
|
|
1294
1287
|
*/
|
|
1295
1288
|
interface GetAuthorizationURLResponse {
|
|
1296
1289
|
authorization_url: string;
|
|
1297
1290
|
}
|
|
1298
|
-
/**
|
|
1299
|
-
* OAuth 콜백 요청
|
|
1300
|
-
*/
|
|
1301
|
-
interface OAuthCallbackRequest {
|
|
1302
|
-
code: string;
|
|
1303
|
-
redirect_uri: string;
|
|
1304
|
-
}
|
|
1305
1291
|
/**
|
|
1306
1292
|
* OAuth 콜백 응답
|
|
1307
1293
|
*/
|
|
@@ -1331,115 +1317,98 @@ declare class OAuthAPI {
|
|
|
1331
1317
|
*/
|
|
1332
1318
|
getEnabledProviders(): Promise<EnabledProvidersResponse>;
|
|
1333
1319
|
/**
|
|
1334
|
-
*
|
|
1335
|
-
*
|
|
1320
|
+
* 소셜 로그인 (중앙 콜백 방식) - 권장
|
|
1321
|
+
* Google Cloud Console에 별도로 redirect_uri를 등록할 필요가 없습니다.
|
|
1322
|
+
* OAuth 완료 후 지정한 콜백 URL로 토큰과 함께 리다이렉트됩니다.
|
|
1336
1323
|
*
|
|
1337
1324
|
* @param provider - OAuth 프로바이더 (google, naver, github, discord)
|
|
1338
|
-
* @param
|
|
1339
|
-
* @
|
|
1325
|
+
* @param callbackUrl - OAuth 완료 후 리다이렉트될 앱의 URL
|
|
1326
|
+
* @param state - 선택적 state 파라미터 (CSRF 방지 등)
|
|
1340
1327
|
*
|
|
1341
1328
|
* @example
|
|
1342
1329
|
* ```typescript
|
|
1343
|
-
*
|
|
1344
|
-
*
|
|
1345
|
-
*
|
|
1346
|
-
*
|
|
1347
|
-
* // 사용자를 OAuth 페이지로 리다이렉트
|
|
1348
|
-
* window.location.href = authorization_url
|
|
1330
|
+
* // 로그인 버튼 클릭 시
|
|
1331
|
+
* await cb.oauth.signIn('google', 'https://myapp.com/oauth/callback')
|
|
1332
|
+
* // Google 로그인 후 https://myapp.com/oauth/callback?access_token=...&refresh_token=... 로 리다이렉트됨
|
|
1349
1333
|
* ```
|
|
1350
|
-
*/
|
|
1351
|
-
getAuthorizationURL(provider: OAuthProvider, options: GetAuthorizationURLRequest): Promise<GetAuthorizationURLResponse>;
|
|
1352
|
-
/**
|
|
1353
|
-
* OAuth 콜백 처리
|
|
1354
|
-
* 소셜 로그인 후 콜백으로 받은 code를 사용하여 로그인을 완료합니다.
|
|
1355
|
-
* 성공 시 자동으로 토큰이 저장됩니다.
|
|
1356
|
-
*
|
|
1357
|
-
* @param provider - OAuth 프로바이더
|
|
1358
|
-
* @param data - code와 redirect_uri
|
|
1359
|
-
* @returns 로그인 결과 (member_id, 토큰, 신규 회원 여부)
|
|
1360
1334
|
*
|
|
1361
1335
|
* @example
|
|
1362
1336
|
* ```typescript
|
|
1363
|
-
* //
|
|
1364
|
-
* const
|
|
1365
|
-
*
|
|
1366
|
-
*
|
|
1367
|
-
*
|
|
1368
|
-
*
|
|
1369
|
-
*
|
|
1370
|
-
*
|
|
1371
|
-
*
|
|
1372
|
-
*
|
|
1373
|
-
* console.log('신규 회원입니다!')
|
|
1337
|
+
* // callback 페이지에서
|
|
1338
|
+
* const result = cb.oauth.getCallbackResult()
|
|
1339
|
+
* if (result) {
|
|
1340
|
+
* if (result.error) {
|
|
1341
|
+
* console.error('로그인 실패:', result.error)
|
|
1342
|
+
* } else {
|
|
1343
|
+
* console.log('로그인 성공:', result.member_id)
|
|
1344
|
+
* // 메인 페이지로 이동
|
|
1345
|
+
* window.location.href = '/'
|
|
1346
|
+
* }
|
|
1374
1347
|
* }
|
|
1375
1348
|
* ```
|
|
1376
1349
|
*/
|
|
1377
|
-
|
|
1350
|
+
signIn(provider: OAuthProvider, callbackUrl: string, state?: string): Promise<void>;
|
|
1378
1351
|
/**
|
|
1379
|
-
* 소셜 로그인
|
|
1380
|
-
*
|
|
1352
|
+
* 소셜 로그인 (팝업 방식)
|
|
1353
|
+
* 팝업 창에서 소셜 로그인을 처리하고 결과를 Promise로 반환합니다.
|
|
1354
|
+
* Google Cloud Console에 별도 등록 불필요.
|
|
1381
1355
|
*
|
|
1382
1356
|
* @param provider - OAuth 프로바이더
|
|
1383
|
-
* @param
|
|
1357
|
+
* @param callbackUrl - OAuth 완료 후 리다이렉트될 팝업의 URL
|
|
1384
1358
|
* @returns 로그인 결과
|
|
1385
1359
|
*
|
|
1386
1360
|
* @example
|
|
1387
1361
|
* ```typescript
|
|
1388
|
-
*
|
|
1389
|
-
* const result = await cb.oauth.signInWithPopup('google', 'https://myapp.com/auth/popup-callback')
|
|
1362
|
+
* const result = await cb.oauth.signInWithPopup('google', 'https://myapp.com/oauth/popup-callback')
|
|
1390
1363
|
* console.log('로그인 성공:', result.member_id)
|
|
1391
1364
|
* ```
|
|
1392
1365
|
*
|
|
1393
1366
|
* @example
|
|
1394
1367
|
* ```html
|
|
1395
1368
|
* <!-- popup-callback.html -->
|
|
1369
|
+
* <script src="https://unpkg.com/connectbase-client"></script>
|
|
1396
1370
|
* <script>
|
|
1397
|
-
* const
|
|
1398
|
-
* const
|
|
1399
|
-
* const error = urlParams.get('error')
|
|
1371
|
+
* const cb = new ConnectBase({ apiKey: 'YOUR_API_KEY' })
|
|
1372
|
+
* const result = cb.oauth.getCallbackResult()
|
|
1400
1373
|
*
|
|
1401
1374
|
* window.opener.postMessage({
|
|
1402
1375
|
* type: 'oauth-callback',
|
|
1403
|
-
*
|
|
1404
|
-
* error
|
|
1376
|
+
* ...result
|
|
1405
1377
|
* }, '*')
|
|
1406
1378
|
* window.close()
|
|
1407
1379
|
* </script>
|
|
1408
1380
|
* ```
|
|
1409
1381
|
*/
|
|
1410
|
-
signInWithPopup(provider: OAuthProvider,
|
|
1382
|
+
signInWithPopup(provider: OAuthProvider, callbackUrl: string): Promise<OAuthCallbackResponse>;
|
|
1411
1383
|
/**
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1414
|
-
*
|
|
1384
|
+
* 콜백 URL에서 OAuth 결과 추출
|
|
1385
|
+
* 중앙 콜백 방식에서 리다이렉트 후 URL 파라미터에서 결과를 추출합니다.
|
|
1386
|
+
* 토큰이 있으면 자동으로 저장됩니다.
|
|
1415
1387
|
*
|
|
1416
|
-
* @
|
|
1417
|
-
* @param redirectUri - 콜백 URL
|
|
1418
|
-
*
|
|
1419
|
-
* @example
|
|
1420
|
-
* ```typescript
|
|
1421
|
-
* // 로그인 버튼 클릭 시
|
|
1422
|
-
* await cb.oauth.signInWithRedirect('google', 'https://myapp.com/auth/callback')
|
|
1423
|
-
* // 페이지가 Google 로그인으로 리다이렉트됨
|
|
1424
|
-
* ```
|
|
1388
|
+
* @returns OAuth 결과 (토큰, member_id 등) 또는 null
|
|
1425
1389
|
*
|
|
1426
1390
|
* @example
|
|
1427
1391
|
* ```typescript
|
|
1428
1392
|
* // callback 페이지에서
|
|
1429
|
-
* const
|
|
1430
|
-
*
|
|
1431
|
-
*
|
|
1432
|
-
*
|
|
1433
|
-
*
|
|
1434
|
-
*
|
|
1435
|
-
*
|
|
1436
|
-
* }
|
|
1437
|
-
* // 로그인 완료, 메인 페이지로 이동
|
|
1438
|
-
* window.location.href = '/'
|
|
1393
|
+
* const result = cb.oauth.getCallbackResult()
|
|
1394
|
+
* if (result) {
|
|
1395
|
+
* if (result.error) {
|
|
1396
|
+
* alert('로그인 실패: ' + result.error)
|
|
1397
|
+
* } else {
|
|
1398
|
+
* console.log('로그인 성공:', result.member_id)
|
|
1399
|
+
* window.location.href = '/'
|
|
1400
|
+
* }
|
|
1439
1401
|
* }
|
|
1440
1402
|
* ```
|
|
1441
1403
|
*/
|
|
1442
|
-
|
|
1404
|
+
getCallbackResult(): {
|
|
1405
|
+
access_token?: string;
|
|
1406
|
+
refresh_token?: string;
|
|
1407
|
+
member_id?: string;
|
|
1408
|
+
is_new_member?: boolean;
|
|
1409
|
+
state?: string;
|
|
1410
|
+
error?: string;
|
|
1411
|
+
} | null;
|
|
1443
1412
|
}
|
|
1444
1413
|
|
|
1445
1414
|
type PaymentStatus = 'pending' | 'ready' | 'in_progress' | 'done' | 'canceled' | 'partial_canceled' | 'aborted' | 'expired' | 'failed';
|
|
@@ -3345,4 +3314,4 @@ declare class ConnectBase {
|
|
|
3345
3314
|
updateConfig(config: Partial<ConnectBaseConfig>): void;
|
|
3346
3315
|
}
|
|
3347
3316
|
|
|
3348
|
-
export { type AnonymousSignInRequest, type AnonymousSignInResponse, type AnonymousSignUpResponse, ApiError, type ApiKeyItem, type AppStatsResponse, AuthError, type AuthSettingsResponse, type BillingCycle, type BillingKeyResponse, type BulkCreateResponse, type BulkError, type CancelPaymentRequest, type CancelPaymentResponse, type CancelSubscriptionRequest, type CategoryInfo, type Channel, type ChannelMembership, type ChargeWithBillingKeyRequest, type ChargeWithBillingKeyResponse, type ChatMessage, type ClientMessage, type ColumnSchema, type CommentListResponse, type ConfirmBillingKeyRequest, type ConfirmPaymentRequest, type ConfirmPaymentResponse, ConnectBase, type ConnectBaseConfig, type ConnectedData, type ConnectionState, type CreateApiKeyRequest, type CreateApiKeyResponse, type CreateChannelRequest, type CreateColumnRequest, type CreateDataRequest, type CreateFolderRequest, type CreateFolderResponse, type CreatePlaylistRequest, type CreateSubscriptionRequest, type CreateTableRequest, type DataItem, type DataType, type DeleteWhereResponse, type DeviceInfo, type EnabledProviderInfo, type EnabledProvidersResponse, type ErrorHandler, type ErrorMessage, type ErrorReport, type ErrorTrackerConfig, type ErrorType, type FetchApiKeysResponse, type FetchDataResponse, type FetchFilesResponse, type FileItem, GameAPI, type GameAction, type GameClientConfig, type GameConnectionState, type GameConnectionStatus, type GameDelta, type GameEventHandlers, type GamePlayer, GameRoom, type GameRoomConfig, type GameRoomInfo, GameRoomTransport, type GameServerMessage, type GameServerMessageType, type GameState, type GameTransportConfig, type
|
|
3317
|
+
export { type AnonymousSignInRequest, type AnonymousSignInResponse, type AnonymousSignUpResponse, ApiError, type ApiKeyItem, type AppStatsResponse, AuthError, type AuthSettingsResponse, type BillingCycle, type BillingKeyResponse, type BulkCreateResponse, type BulkError, type CancelPaymentRequest, type CancelPaymentResponse, type CancelSubscriptionRequest, type CategoryInfo, type Channel, type ChannelMembership, type ChargeWithBillingKeyRequest, type ChargeWithBillingKeyResponse, type ChatMessage, type ClientMessage, type ColumnSchema, type CommentListResponse, type ConfirmBillingKeyRequest, type ConfirmPaymentRequest, type ConfirmPaymentResponse, ConnectBase, type ConnectBaseConfig, type ConnectedData, type ConnectionState, type CreateApiKeyRequest, type CreateApiKeyResponse, type CreateChannelRequest, type CreateColumnRequest, type CreateDataRequest, type CreateFolderRequest, type CreateFolderResponse, type CreatePlaylistRequest, type CreateSubscriptionRequest, type CreateTableRequest, type DataItem, type DataType, type DeleteWhereResponse, type DeviceInfo, type EnabledProviderInfo, type EnabledProvidersResponse, type ErrorHandler, type ErrorMessage, type ErrorReport, type ErrorTrackerConfig, type ErrorType, type FetchApiKeysResponse, type FetchDataResponse, type FetchFilesResponse, type FileItem, GameAPI, type GameAction, type GameClientConfig, type GameConnectionState, type GameConnectionStatus, type GameDelta, type GameEventHandlers, type GamePlayer, GameRoom, type GameRoomConfig, type GameRoomInfo, GameRoomTransport, type GameServerMessage, type GameServerMessageType, type GameState, type GameTransportConfig, type GetAuthorizationURLResponse, type GuestMemberSignInResponse, type HistoryResponse, type ICEServer, type ICEServersResponse, type InitUploadResponse, type InvokeFunctionRequest, type InvokeFunctionResponse, type IssueBillingKeyRequest, type IssueBillingKeyResponse, type JoinRoomRequest, type JoinRoomResponse, type ListBillingKeysResponse, type ListSubscriptionPaymentsRequest, type ListSubscriptionPaymentsResponse, type ListSubscriptionsRequest, type ListSubscriptionsResponse, type MemberSignInRequest, type MemberSignInResponse, type MemberSignUpRequest, type MemberSignUpResponse, type MembershipTier, type MessageHandler, type MoveFileRequest, type OAuthCallbackResponse, type OAuthProvider, type PauseSubscriptionRequest, type PaymentDetail, type PaymentStatus, type PeerInfo, type PlayerEvent, type Playlist, type PlaylistItem, type PongMessage, type PreparePaymentRequest, type PreparePaymentResponse, type PushPlatform, type QualityProgress, type QueryOptions, type RealtimeConnectOptions, type RealtimeMessage, type RegisterDeviceRequest, type RenameFileRequest, type RenameFileResponse, type RoomInfo, type RoomStats, type RoomsResponse, type SendOptions, type ServerMessage, type Shorts, type ShortsListResponse, type SignInRequest, type SignInResponse, type SignUpRequest, type SignUpResponse, type SignalingMessage, type SignalingMessageType, type StateChange, type StateChangeHandler, type StreamURLResponse, type SubscribeOptions, type SubscribeTopicRequest, type SubscribedData, type Subscription, type SubscriptionPaymentResponse, type SubscriptionPaymentStatus, type SubscriptionResponse, type SubscriptionStatus, type SuperChat, type TableSchema, type TranscodeStatus, type TransportType, type UpdateApiKeyRequest, type UpdateApiKeyResponse, type UpdateBillingKeyRequest, type UpdateChannelRequest, type UpdateColumnRequest, type UpdateDataRequest, type UpdateSubscriptionRequest, type UpdateVideoRequest, type UploadFileResponse, type UploadOptions, type UploadProgress, type UserInfo, type VAPIDPublicKeyResponse, type Video, type VideoComment, type VideoListOptions, type VideoListResponse, VideoProcessingError, type VideoQuality, type VideoStatus, type VideoVisibility, type WaitOptions, type WatchHistoryItem, type WebPushSubscription, type WebRTCConnectOptions, type WebRTCConnectionState, type WebRTCMode, type WhereCondition, type WhereOperator, ConnectBase as default, isWebTransportSupported };
|
package/dist/index.js
CHANGED
|
@@ -2027,109 +2027,88 @@ var OAuthAPI = class {
|
|
|
2027
2027
|
return this.http.get("/v1/public/oauth/providers");
|
|
2028
2028
|
}
|
|
2029
2029
|
/**
|
|
2030
|
-
*
|
|
2031
|
-
*
|
|
2030
|
+
* 소셜 로그인 (중앙 콜백 방식) - 권장
|
|
2031
|
+
* Google Cloud Console에 별도로 redirect_uri를 등록할 필요가 없습니다.
|
|
2032
|
+
* OAuth 완료 후 지정한 콜백 URL로 토큰과 함께 리다이렉트됩니다.
|
|
2032
2033
|
*
|
|
2033
2034
|
* @param provider - OAuth 프로바이더 (google, naver, github, discord)
|
|
2034
|
-
* @param
|
|
2035
|
-
* @
|
|
2035
|
+
* @param callbackUrl - OAuth 완료 후 리다이렉트될 앱의 URL
|
|
2036
|
+
* @param state - 선택적 state 파라미터 (CSRF 방지 등)
|
|
2036
2037
|
*
|
|
2037
2038
|
* @example
|
|
2038
2039
|
* ```typescript
|
|
2039
|
-
*
|
|
2040
|
-
*
|
|
2041
|
-
*
|
|
2042
|
-
*
|
|
2043
|
-
* // 사용자를 OAuth 페이지로 리다이렉트
|
|
2044
|
-
* window.location.href = authorization_url
|
|
2040
|
+
* // 로그인 버튼 클릭 시
|
|
2041
|
+
* await cb.oauth.signIn('google', 'https://myapp.com/oauth/callback')
|
|
2042
|
+
* // Google 로그인 후 https://myapp.com/oauth/callback?access_token=...&refresh_token=... 로 리다이렉트됨
|
|
2045
2043
|
* ```
|
|
2046
|
-
*/
|
|
2047
|
-
async getAuthorizationURL(provider, options) {
|
|
2048
|
-
const params = new URLSearchParams({
|
|
2049
|
-
redirect_uri: options.redirect_uri
|
|
2050
|
-
});
|
|
2051
|
-
if (options.state) {
|
|
2052
|
-
params.append("state", options.state);
|
|
2053
|
-
}
|
|
2054
|
-
return this.http.get(
|
|
2055
|
-
`/v1/public/oauth/${provider}/authorize?${params.toString()}`
|
|
2056
|
-
);
|
|
2057
|
-
}
|
|
2058
|
-
/**
|
|
2059
|
-
* OAuth 콜백 처리
|
|
2060
|
-
* 소셜 로그인 후 콜백으로 받은 code를 사용하여 로그인을 완료합니다.
|
|
2061
|
-
* 성공 시 자동으로 토큰이 저장됩니다.
|
|
2062
|
-
*
|
|
2063
|
-
* @param provider - OAuth 프로바이더
|
|
2064
|
-
* @param data - code와 redirect_uri
|
|
2065
|
-
* @returns 로그인 결과 (member_id, 토큰, 신규 회원 여부)
|
|
2066
2044
|
*
|
|
2067
2045
|
* @example
|
|
2068
2046
|
* ```typescript
|
|
2069
|
-
* //
|
|
2070
|
-
* const
|
|
2071
|
-
*
|
|
2072
|
-
*
|
|
2073
|
-
*
|
|
2074
|
-
*
|
|
2075
|
-
*
|
|
2076
|
-
*
|
|
2077
|
-
*
|
|
2078
|
-
*
|
|
2079
|
-
* console.log('신규 회원입니다!')
|
|
2047
|
+
* // callback 페이지에서
|
|
2048
|
+
* const result = cb.oauth.getCallbackResult()
|
|
2049
|
+
* if (result) {
|
|
2050
|
+
* if (result.error) {
|
|
2051
|
+
* console.error('로그인 실패:', result.error)
|
|
2052
|
+
* } else {
|
|
2053
|
+
* console.log('로그인 성공:', result.member_id)
|
|
2054
|
+
* // 메인 페이지로 이동
|
|
2055
|
+
* window.location.href = '/'
|
|
2056
|
+
* }
|
|
2080
2057
|
* }
|
|
2081
2058
|
* ```
|
|
2082
2059
|
*/
|
|
2083
|
-
async
|
|
2084
|
-
const
|
|
2085
|
-
|
|
2086
|
-
|
|
2060
|
+
async signIn(provider, callbackUrl, state) {
|
|
2061
|
+
const params = new URLSearchParams({ app_callback: callbackUrl });
|
|
2062
|
+
if (state) {
|
|
2063
|
+
params.append("state", state);
|
|
2064
|
+
}
|
|
2065
|
+
const response = await this.http.get(
|
|
2066
|
+
`/v1/public/oauth/${provider}/authorize/central?${params.toString()}`
|
|
2087
2067
|
);
|
|
2088
|
-
|
|
2089
|
-
return response;
|
|
2068
|
+
window.location.href = response.authorization_url;
|
|
2090
2069
|
}
|
|
2091
2070
|
/**
|
|
2092
|
-
* 소셜 로그인
|
|
2093
|
-
*
|
|
2071
|
+
* 소셜 로그인 (팝업 방식)
|
|
2072
|
+
* 팝업 창에서 소셜 로그인을 처리하고 결과를 Promise로 반환합니다.
|
|
2073
|
+
* Google Cloud Console에 별도 등록 불필요.
|
|
2094
2074
|
*
|
|
2095
2075
|
* @param provider - OAuth 프로바이더
|
|
2096
|
-
* @param
|
|
2076
|
+
* @param callbackUrl - OAuth 완료 후 리다이렉트될 팝업의 URL
|
|
2097
2077
|
* @returns 로그인 결과
|
|
2098
2078
|
*
|
|
2099
2079
|
* @example
|
|
2100
2080
|
* ```typescript
|
|
2101
|
-
*
|
|
2102
|
-
* const result = await cb.oauth.signInWithPopup('google', 'https://myapp.com/auth/popup-callback')
|
|
2081
|
+
* const result = await cb.oauth.signInWithPopup('google', 'https://myapp.com/oauth/popup-callback')
|
|
2103
2082
|
* console.log('로그인 성공:', result.member_id)
|
|
2104
2083
|
* ```
|
|
2105
2084
|
*
|
|
2106
2085
|
* @example
|
|
2107
2086
|
* ```html
|
|
2108
2087
|
* <!-- popup-callback.html -->
|
|
2088
|
+
* <script src="https://unpkg.com/connectbase-client"></script>
|
|
2109
2089
|
* <script>
|
|
2110
|
-
* const
|
|
2111
|
-
* const
|
|
2112
|
-
* const error = urlParams.get('error')
|
|
2090
|
+
* const cb = new ConnectBase({ apiKey: 'YOUR_API_KEY' })
|
|
2091
|
+
* const result = cb.oauth.getCallbackResult()
|
|
2113
2092
|
*
|
|
2114
2093
|
* window.opener.postMessage({
|
|
2115
2094
|
* type: 'oauth-callback',
|
|
2116
|
-
*
|
|
2117
|
-
* error
|
|
2095
|
+
* ...result
|
|
2118
2096
|
* }, '*')
|
|
2119
2097
|
* window.close()
|
|
2120
2098
|
* </script>
|
|
2121
2099
|
* ```
|
|
2122
2100
|
*/
|
|
2123
|
-
async signInWithPopup(provider,
|
|
2124
|
-
const
|
|
2125
|
-
|
|
2126
|
-
|
|
2101
|
+
async signInWithPopup(provider, callbackUrl) {
|
|
2102
|
+
const params = new URLSearchParams({ app_callback: callbackUrl });
|
|
2103
|
+
const response = await this.http.get(
|
|
2104
|
+
`/v1/public/oauth/${provider}/authorize/central?${params.toString()}`
|
|
2105
|
+
);
|
|
2127
2106
|
const width = 500;
|
|
2128
2107
|
const height = 600;
|
|
2129
2108
|
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
2130
2109
|
const top = window.screenY + (window.outerHeight - height) / 2;
|
|
2131
2110
|
const popup = window.open(
|
|
2132
|
-
authorization_url,
|
|
2111
|
+
response.authorization_url,
|
|
2133
2112
|
"oauth-popup",
|
|
2134
2113
|
`width=${width},height=${height},left=${left},top=${top}`
|
|
2135
2114
|
);
|
|
@@ -2144,19 +2123,14 @@ var OAuthAPI = class {
|
|
|
2144
2123
|
reject(new Error(event.data.error));
|
|
2145
2124
|
return;
|
|
2146
2125
|
}
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
});
|
|
2156
|
-
resolve(result);
|
|
2157
|
-
} catch (error) {
|
|
2158
|
-
reject(error);
|
|
2159
|
-
}
|
|
2126
|
+
const result = {
|
|
2127
|
+
member_id: event.data.member_id,
|
|
2128
|
+
access_token: event.data.access_token,
|
|
2129
|
+
refresh_token: event.data.refresh_token,
|
|
2130
|
+
is_new_member: event.data.is_new_member === "true" || event.data.is_new_member === true
|
|
2131
|
+
};
|
|
2132
|
+
this.http.setTokens(result.access_token, result.refresh_token);
|
|
2133
|
+
resolve(result);
|
|
2160
2134
|
};
|
|
2161
2135
|
window.addEventListener("message", handleMessage);
|
|
2162
2136
|
const checkClosed = setInterval(() => {
|
|
@@ -2169,41 +2143,46 @@ var OAuthAPI = class {
|
|
|
2169
2143
|
});
|
|
2170
2144
|
}
|
|
2171
2145
|
/**
|
|
2172
|
-
*
|
|
2173
|
-
*
|
|
2174
|
-
*
|
|
2146
|
+
* 콜백 URL에서 OAuth 결과 추출
|
|
2147
|
+
* 중앙 콜백 방식에서 리다이렉트 후 URL 파라미터에서 결과를 추출합니다.
|
|
2148
|
+
* 토큰이 있으면 자동으로 저장됩니다.
|
|
2175
2149
|
*
|
|
2176
|
-
* @
|
|
2177
|
-
* @param redirectUri - 콜백 URL
|
|
2178
|
-
*
|
|
2179
|
-
* @example
|
|
2180
|
-
* ```typescript
|
|
2181
|
-
* // 로그인 버튼 클릭 시
|
|
2182
|
-
* await cb.oauth.signInWithRedirect('google', 'https://myapp.com/auth/callback')
|
|
2183
|
-
* // 페이지가 Google 로그인으로 리다이렉트됨
|
|
2184
|
-
* ```
|
|
2150
|
+
* @returns OAuth 결과 (토큰, member_id 등) 또는 null
|
|
2185
2151
|
*
|
|
2186
2152
|
* @example
|
|
2187
2153
|
* ```typescript
|
|
2188
2154
|
* // callback 페이지에서
|
|
2189
|
-
* const
|
|
2190
|
-
*
|
|
2191
|
-
*
|
|
2192
|
-
*
|
|
2193
|
-
*
|
|
2194
|
-
*
|
|
2195
|
-
*
|
|
2196
|
-
* }
|
|
2197
|
-
* // 로그인 완료, 메인 페이지로 이동
|
|
2198
|
-
* window.location.href = '/'
|
|
2155
|
+
* const result = cb.oauth.getCallbackResult()
|
|
2156
|
+
* if (result) {
|
|
2157
|
+
* if (result.error) {
|
|
2158
|
+
* alert('로그인 실패: ' + result.error)
|
|
2159
|
+
* } else {
|
|
2160
|
+
* console.log('로그인 성공:', result.member_id)
|
|
2161
|
+
* window.location.href = '/'
|
|
2162
|
+
* }
|
|
2199
2163
|
* }
|
|
2200
2164
|
* ```
|
|
2201
2165
|
*/
|
|
2202
|
-
|
|
2203
|
-
const
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2166
|
+
getCallbackResult() {
|
|
2167
|
+
const params = new URLSearchParams(window.location.search);
|
|
2168
|
+
const error = params.get("error");
|
|
2169
|
+
if (error) {
|
|
2170
|
+
return { error };
|
|
2171
|
+
}
|
|
2172
|
+
const accessToken = params.get("access_token");
|
|
2173
|
+
const refreshToken = params.get("refresh_token");
|
|
2174
|
+
const memberId = params.get("member_id");
|
|
2175
|
+
if (!accessToken || !refreshToken || !memberId) {
|
|
2176
|
+
return null;
|
|
2177
|
+
}
|
|
2178
|
+
this.http.setTokens(accessToken, refreshToken);
|
|
2179
|
+
return {
|
|
2180
|
+
access_token: accessToken,
|
|
2181
|
+
refresh_token: refreshToken,
|
|
2182
|
+
member_id: memberId,
|
|
2183
|
+
is_new_member: params.get("is_new_member") === "true",
|
|
2184
|
+
state: params.get("state") || void 0
|
|
2185
|
+
};
|
|
2207
2186
|
}
|
|
2208
2187
|
};
|
|
2209
2188
|
|