@infoteam/account-server 0.6.1 → 0.7.0

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 GSA Infoteam
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GSA Infoteam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,51 +1,51 @@
1
- # @infoteam/account-server
2
-
3
- 서비스 백엔드용 인포팀 계정(IdP) 클라이언트. 특정 프레임워크에 의존하지 않고 `fetch`만 쓴다. NestJS라면 [`@infoteam/account-nest`](../nest)를 쓴다.
4
-
5
- 이 패키지는 IdP로 사용자를 확인하는 데까지만 맡는다. [서비스 세션](../../README.md#서비스-세션)(토큰 발급, 갱신, 로그아웃)은 서비스가
6
- [세션 프로토콜](../../README.md#세션-프로토콜)에 맞춰 직접 구현한다.
7
-
8
- ## 설치
9
-
10
- ```bash
11
- pnpm add @infoteam/account-server zod
12
- ```
13
-
14
- ## 사용
15
-
16
- ```ts
17
- import { createAccountServer } from '@infoteam/account-server';
18
-
19
- const account = createAccountServer({
20
- issuer: 'production',
21
- clientId: process.env.ACCOUNT_CLIENT_ID!,
22
- clientSecret: process.env.ACCOUNT_CLIENT_SECRET,
23
- requiredScopes: ['name', 'email'], // client 에 필수로 등록한 scope
24
- clientCredentialsScopes: ['name'], // getUserInfoBySub 를 쓸 때만. client 에 등록한 scope 여야 한다
25
- });
26
-
27
- // 프론트가 callback 에서 받은 값을 그대로 넘긴다
28
- const { user } = await account.loginWithCode({ code, codeVerifier, redirectUri, nonce });
29
- user.name; // string
30
- user.studentId; // string | undefined
31
- ```
32
-
33
- - `loginWithCode`는 code를 confidential client로서 교환하고, 응답에 담긴 id_token으로 사용자를 만든다. 그래서 프론트는 `openid`를 요청해야 한다(웹과 Flutter SDK는 항상 요청한다).
34
- - `requiredScopes`의 필드는 `loginWithCode` 결과에서 필수 타입이 된다. id_token에 필드가 빠져 있으면 `missing_claims`로 실패한다. `profile`과 `picture`는
35
- 사용자가 비워 둘 수 있어서 예외다.
36
- - `getUserInfoBySub` 결과에서는 `clientCredentialsScopes` 중 `requiredScopes`에도 있는 필드만 필수 타입이다. 선택 scope는 사용자가 거절했을 수 있어서, 그 필드는 `undefined`일 수 있다.
37
- - `requiredScopes`에는 client에 **필수로** 등록한 scope만 넣는다. 선택 scope를 넣으면 그 scope를 거부한 사용자는 로그인하지 못한다.
38
- - `loginWithCode(params, { maxAge: 300, amr: ['hwk'] })`처럼 로그인 조건을 요구할 수 있다. IdP에 로그인한 지 5분이 넘었거나 패스키로 로그인하지 않았으면
39
- `insufficient_authentication`으로 실패한다. account에 2FA가 생기면 같은 자리에서 확인한다.
40
-
41
- ## 메서드
42
-
43
- | 메서드 | 기능 | secret |
44
- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------ | --------- |
45
- | `loginWithCode(params)` | code를 교환하고 id_token으로 사용자를 만든다 | 필요 |
46
- | `getUserInfoBySub(sub)` | client credentials 토큰으로 사용자 조회. 이 client에 동의하지 않았거나 없는 사용자면 `null`. 토큰은 캐시한다 | 필요 |
47
- | `verifyIdToken(idToken)` | 앱이 보낸 id_token 검증 | 필요 없음 |
48
- | `revoke({ token, tokenTypeHint })` | 토큰 폐기 | 필요 없음 |
49
- | `verifyRegistration()` | IdP 등록 정보와 `requiredScopes`, 인증 방식 대조 | 필요 없음 |
50
-
51
- 실패하면 `AccountError`를 던지므로 `code`로 경우를 나눈다.
1
+ # @infoteam/account-server
2
+
3
+ 서비스 백엔드용 인포팀 계정(IdP) 클라이언트. 특정 프레임워크에 의존하지 않고 `fetch`만 쓴다. NestJS라면 [`@infoteam/account-nest`](../nest)를 쓴다.
4
+
5
+ 이 패키지는 IdP로 사용자를 확인하는 데까지만 맡는다. [서비스 세션](../../README.md#서비스-세션)(토큰 발급, 갱신, 로그아웃)은 서비스가
6
+ [세션 프로토콜](../../README.md#세션-프로토콜)에 맞춰 직접 구현한다.
7
+
8
+ ## 설치
9
+
10
+ ```bash
11
+ pnpm add @infoteam/account-server zod
12
+ ```
13
+
14
+ ## 사용
15
+
16
+ ```ts
17
+ import { createAccountServer } from '@infoteam/account-server';
18
+
19
+ const account = createAccountServer({
20
+ issuer: 'production',
21
+ clientId: process.env.ACCOUNT_CLIENT_ID!,
22
+ clientSecret: process.env.ACCOUNT_CLIENT_SECRET,
23
+ requiredScopes: ['name', 'email'], // client 에 필수로 등록한 scope
24
+ clientCredentialsScopes: ['name'], // getUserInfoBySub 를 쓸 때만. client 에 등록한 scope 여야 한다
25
+ });
26
+
27
+ // 프론트가 callback 에서 받은 값을 그대로 넘긴다
28
+ const { user } = await account.loginWithCode({ code, codeVerifier, redirectUri, nonce });
29
+ user.name; // string
30
+ user.studentId; // string | undefined
31
+ ```
32
+
33
+ - `loginWithCode`는 code를 confidential client로서 교환하고, 응답에 담긴 id_token으로 사용자를 만든다. 그래서 프론트는 `openid`를 요청해야 한다(웹과 Flutter SDK는 항상 요청한다).
34
+ - `requiredScopes`의 필드는 `loginWithCode` 결과에서 필수 타입이 된다. id_token에 필드가 빠져 있으면 `missing_claims`로 실패한다. `profile`과 `picture`는
35
+ 사용자가 비워 둘 수 있어서 예외다.
36
+ - `getUserInfoBySub` 결과에서는 `clientCredentialsScopes` 중 `requiredScopes`에도 있는 필드만 필수 타입이다. 선택 scope는 사용자가 거절했을 수 있어서, 그 필드는 `undefined`일 수 있다.
37
+ - `requiredScopes`에는 client에 **필수로** 등록한 scope만 넣는다. 선택 scope를 넣으면 그 scope를 거부한 사용자는 로그인하지 못한다.
38
+ - `loginWithCode(params, { maxAge: 300, amr: ['hwk'] })`처럼 로그인 조건을 요구할 수 있다. IdP에 로그인한 지 5분이 넘었거나 패스키로 로그인하지 않았으면
39
+ `insufficient_authentication`으로 실패한다. account에 2FA가 생기면 같은 자리에서 확인한다.
40
+
41
+ ## 메서드
42
+
43
+ | 메서드 | 기능 | secret |
44
+ | ---------------------------------- | ------------------------------------------------------------------------------------------------------------ | --------- |
45
+ | `loginWithCode(params)` | code를 교환하고 id_token으로 사용자를 만든다 | 필요 |
46
+ | `getUserInfoBySub(sub)` | client credentials 토큰으로 사용자 조회. 이 client에 동의하지 않았거나 없는 사용자면 `null`. 토큰은 캐시한다 | 필요 |
47
+ | `verifyIdToken(idToken)` | 앱이 보낸 id_token 검증 | 필요 없음 |
48
+ | `revoke({ token, tokenTypeHint })` | 토큰 폐기 | 필요 없음 |
49
+ | `verifyRegistration()` | IdP 등록 정보와 `requiredScopes`, 인증 방식 대조 | 필요 없음 |
50
+
51
+ 실패하면 `AccountError`를 던지므로 `code`로 경우를 나눈다.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AccountError, AccountErrorCode, AccountMetadata, AccountMetadata as AccountMetadata$1, ClientScope, ClientScope as ClientScope$1, ENVIRONMENTS, Environment, ExchangeCodeParams, ExchangeCodeParams as ExchangeCodeParams$1, IdTokenClaims, IdTokenClaims as IdTokenClaims$1, IssuerInput, IssuerInput as IssuerInput$1, RevokeParams, RevokeParams as RevokeParams$1, Scope, TokenResponse, TokenResponse as TokenResponse$1, UserInfo, UserInfo as UserInfo$1 } from "@infoteam/account-core";
1
+ import { AccountError, AccountErrorCode, AccountMetadata, AccountMetadata as AccountMetadata$1, ClientScope, ClientScope as ClientScope$1, ENVIRONMENTS, Environment, ExchangeCodeParams, ExchangeCodeParams as ExchangeCodeParams$1, IdTokenClaims, IdTokenClaims as IdTokenClaims$1, IssuerInput, IssuerInput as IssuerInput$1, LoginCodeBodySchema, LoginRequestBody, LoginTicketBodySchema, RevokeParams, RevokeParams as RevokeParams$1, SESSION_REJECTED, Scope, SessionRejectedResponse, SessionTokensResponse, SessionTokensResponseSchema, SessionTransport, TokenResponse, TokenResponse as TokenResponse$1, UserInfo, UserInfo as UserInfo$1 } from "@infoteam/account-core";
2
2
  import * as z from "zod/mini";
3
3
  //#region src/options.d.ts
4
4
  /** 값은 보통 환경 변수에서 오므로, 첫 요청이 아니라 서버가 시작될 때 검증한다. */
@@ -8,19 +8,19 @@ export declare const AccountServerOptionsSchema: z.ZodMiniObject<{
8
8
  clientSecret: z.ZodMiniOptional<z.ZodMiniString<string>>;
9
9
  requiredScopes: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniEnum<{
10
10
  email: "email";
11
- profile: "profile";
12
11
  name: "name";
12
+ profile: "profile";
13
13
  picture: "picture";
14
- phone_number: "phone_number";
15
14
  student_id: "student_id";
15
+ phone_number: "phone_number";
16
16
  }>>>;
17
17
  clientCredentialsScopes: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniEnum<{
18
18
  email: "email";
19
- profile: "profile";
20
19
  name: "name";
20
+ profile: "profile";
21
21
  picture: "picture";
22
- phone_number: "phone_number";
23
22
  student_id: "student_id";
23
+ phone_number: "phone_number";
24
24
  }>>>;
25
25
  fetch: z.ZodMiniOptional<z.ZodMiniCustom<typeof fetch, typeof fetch>>;
26
26
  }, z.core.$strip>;
@@ -86,4 +86,4 @@ interface AccountServer<RequiredScope extends ClientScope$1 = never, LookupScope
86
86
  /** @throws {@link AccountError} 옵션이 없거나 비어 있으면 `invalid_request`. */
87
87
  export declare function createAccountServer<const RequiredScopes extends readonly ClientScope$1[] = [], const LookupScopes extends readonly ClientScope$1[] = []>(input: AccountServerOptions<RequiredScopes, LookupScopes>): AccountServer<RequiredScopes[number], LookupScopes[number]>;
88
88
  //#endregion
89
- export { AccountError, type AccountErrorCode, type AccountMetadata, type AccountServer, type AccountServerOptions, type AuthenticationRequirement, type ClientScope, ENVIRONMENTS, type Environment, type ExchangeCodeParams, type IdTokenClaims, type IssuerInput, type LoginWithCodeParams, type RevokeParams, type Scope, type TokenResponse, type UserInfo };
89
+ export { AccountError, type AccountErrorCode, type AccountMetadata, type AccountServer, type AccountServerOptions, type AuthenticationRequirement, type ClientScope, ENVIRONMENTS, type Environment, type ExchangeCodeParams, type IdTokenClaims, type IssuerInput, LoginCodeBodySchema, type LoginRequestBody, LoginTicketBodySchema, type LoginWithCodeParams, type RevokeParams, SESSION_REJECTED, type Scope, type SessionRejectedResponse, type SessionTokensResponse, SessionTokensResponseSchema, type SessionTransport, type TokenResponse, type UserInfo };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AccountError, AccountError as AccountError$1, CLIENT_TOKEN_REFRESH_MARGIN_MS, ClientScopeSchema, ENVIRONMENTS, discover, exchangeCode, fetchClientRegistration, fetchUserInfo, requestClientCredentials, revokeToken, userInfoFromIdToken, verifyIdToken } from "@infoteam/account-core";
1
+ import { AccountError, AccountError as AccountError$1, CLIENT_TOKEN_REFRESH_MARGIN_MS, ClientScopeSchema, ENVIRONMENTS, LoginCodeBodySchema, LoginTicketBodySchema, SESSION_REJECTED, SessionTokensResponseSchema, discover, exchangeCode, fetchClientRegistration, fetchUserInfo, requestClientCredentials, revokeToken, userInfoFromIdToken, verifyIdToken } from "@infoteam/account-core";
2
2
  import * as z from "zod/mini";
3
3
  import { Mutex, isFunction, isString } from "es-toolkit";
4
4
  //#region src/client-token-cache.ts
@@ -124,4 +124,4 @@ function checkAuthentication(claims, { maxAge, amr }) {
124
124
  if (amr && !amr.some((method) => claims.amr?.includes(method))) throw new AccountError$1("insufficient_authentication", { description: `the IdP login used ${claims.amr?.join(" ") || "an unknown method"}, not ${amr.join(" or ")}` });
125
125
  }
126
126
  //#endregion
127
- export { AccountError, AccountServerOptionsSchema, ENVIRONMENTS, createAccountServer };
127
+ export { AccountError, AccountServerOptionsSchema, ENVIRONMENTS, LoginCodeBodySchema, LoginTicketBodySchema, SESSION_REJECTED, SessionTokensResponseSchema, createAccountServer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infoteam/account-server",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Backend client for the Infoteam account IdP: code exchange with id_token login and user lookup with client credentials",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -31,7 +31,7 @@
31
31
  "node": ">=20.19"
32
32
  },
33
33
  "dependencies": {
34
- "@infoteam/account-core": "^0.6.1",
34
+ "@infoteam/account-core": "^0.7.0",
35
35
  "es-toolkit": "^1.52.0"
36
36
  },
37
37
  "peerDependencies": {