isa-auth-server 0.0.0-stage → 0.2.3

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.
@@ -0,0 +1,144 @@
1
+ interface OAuthProviderServerConfig {
2
+ clientId: string;
3
+ clientSecret: string;
4
+ redirectUri?: string;
5
+ scope?: string[];
6
+ }
7
+ interface JwtServerConfig {
8
+ secret: string;
9
+ issuer?: string;
10
+ audience?: string;
11
+ expiresInSeconds?: number;
12
+ }
13
+ interface ServerAuthConfig {
14
+ jwt: JwtServerConfig;
15
+ providers?: {
16
+ google?: OAuthProviderServerConfig;
17
+ github?: OAuthProviderServerConfig;
18
+ kakao?: OAuthProviderServerConfig;
19
+ naver?: OAuthProviderServerConfig;
20
+ apple?: OAuthProviderServerConfig;
21
+ discord?: OAuthProviderServerConfig;
22
+ line?: OAuthProviderServerConfig;
23
+ meta?: OAuthProviderServerConfig;
24
+ [key: string]: OAuthProviderServerConfig | undefined;
25
+ };
26
+ worldId?: {
27
+ appId: string;
28
+ action?: string;
29
+ };
30
+ passkey?: {
31
+ rpId: string;
32
+ origin: string;
33
+ };
34
+ onUserResolved?: (user: any, provider: string, raw: any) => Promise<any> | any;
35
+ }
36
+ interface TokenExchangePayload {
37
+ type: 'oauth_code' | 'world_id_proof' | 'passkey_assertion' | 'web3_signature';
38
+ provider?: string;
39
+ code?: string;
40
+ redirectUri?: string;
41
+ state?: string;
42
+ codeVerifier?: string;
43
+ proof?: any;
44
+ action?: string;
45
+ signal?: string;
46
+ assertion?: any;
47
+ challenge?: string;
48
+ address?: string;
49
+ signature?: string;
50
+ message?: string;
51
+ chainId?: number;
52
+ }
53
+ interface TokenExchangeResponse {
54
+ accessToken: string;
55
+ refreshToken?: string;
56
+ expiresIn: number;
57
+ tokenType: string;
58
+ user: {
59
+ id: string;
60
+ name?: string;
61
+ email?: string;
62
+ avatar?: string;
63
+ roles?: string[];
64
+ permissions?: string[];
65
+ [key: string]: any;
66
+ };
67
+ raw?: any;
68
+ }
69
+
70
+ declare class JwtServerService {
71
+ private config;
72
+ constructor(config: JwtServerConfig);
73
+ sign(payload: Record<string, any>, customExpiresIn?: number): string;
74
+ verify(token: string): any | null;
75
+ }
76
+
77
+ declare class OAuthExchanger {
78
+ private configs;
79
+ constructor(configs?: Record<string, OAuthProviderServerConfig>);
80
+ exchangeCode(providerName: string, code: string, options?: {
81
+ redirectUri?: string;
82
+ codeVerifier?: string;
83
+ state?: string;
84
+ }): Promise<{
85
+ rawToken: any;
86
+ profile: any;
87
+ }>;
88
+ private normalizeProfile;
89
+ }
90
+
91
+ /**
92
+ * Server-side verifiers for Web3 SIWE, World ID, and Passkey WebAuthn
93
+ */
94
+ interface SiweParsedMessage {
95
+ domain: string;
96
+ address: string;
97
+ statement?: string;
98
+ uri: string;
99
+ version: string;
100
+ chainId: number;
101
+ nonce: string;
102
+ issuedAt: string;
103
+ expirationTime?: string;
104
+ }
105
+ declare function parseSiweMessage(message: string): SiweParsedMessage | null;
106
+ declare function verifyWorldIdProof(appId: string, action: string, proofPayload: any): Promise<{
107
+ success: boolean;
108
+ nullifierHash?: string;
109
+ error?: string;
110
+ }>;
111
+ declare function verifyPasskeyAssertionFormat(assertion: any, expectedChallenge?: string): {
112
+ success: boolean;
113
+ userHandle?: string;
114
+ error?: string;
115
+ };
116
+
117
+ declare class IsaAuthServer {
118
+ private config;
119
+ private jwtService;
120
+ private oauthExchanger;
121
+ constructor(config: ServerAuthConfig);
122
+ handleExchange(payload: TokenExchangePayload): Promise<TokenExchangeResponse>;
123
+ verifyToken(token: string): any | null;
124
+ }
125
+
126
+ declare function createExpressHandler(server: IsaAuthServer): (req: any, res: any) => Promise<any>;
127
+ declare function createExpressAuthMiddleware(server: IsaAuthServer): (req: any, res: any, next: () => void) => any;
128
+
129
+ /**
130
+ * Next.js Pages Router API Handler:
131
+ * Usage:
132
+ * // pages/api/auth/exchange.ts
133
+ * export default createNextApiHandler(authServer);
134
+ */
135
+ declare function createNextApiHandler(server: IsaAuthServer): (req: any, res: any) => Promise<any>;
136
+ /**
137
+ * Next.js App Router Route Handler:
138
+ * Usage:
139
+ * // app/api/auth/exchange/route.ts
140
+ * export const POST = createNextRouteHandler(authServer);
141
+ */
142
+ declare function createNextRouteHandler(server: IsaAuthServer): (request: Request) => Promise<Response>;
143
+
144
+ export { IsaAuthServer, type JwtServerConfig, JwtServerService, OAuthExchanger, type OAuthProviderServerConfig, type ServerAuthConfig, type SiweParsedMessage, type TokenExchangePayload, type TokenExchangeResponse, createExpressAuthMiddleware, createExpressHandler, createNextApiHandler, createNextRouteHandler, parseSiweMessage, verifyPasskeyAssertionFormat, verifyWorldIdProof };
@@ -0,0 +1,144 @@
1
+ interface OAuthProviderServerConfig {
2
+ clientId: string;
3
+ clientSecret: string;
4
+ redirectUri?: string;
5
+ scope?: string[];
6
+ }
7
+ interface JwtServerConfig {
8
+ secret: string;
9
+ issuer?: string;
10
+ audience?: string;
11
+ expiresInSeconds?: number;
12
+ }
13
+ interface ServerAuthConfig {
14
+ jwt: JwtServerConfig;
15
+ providers?: {
16
+ google?: OAuthProviderServerConfig;
17
+ github?: OAuthProviderServerConfig;
18
+ kakao?: OAuthProviderServerConfig;
19
+ naver?: OAuthProviderServerConfig;
20
+ apple?: OAuthProviderServerConfig;
21
+ discord?: OAuthProviderServerConfig;
22
+ line?: OAuthProviderServerConfig;
23
+ meta?: OAuthProviderServerConfig;
24
+ [key: string]: OAuthProviderServerConfig | undefined;
25
+ };
26
+ worldId?: {
27
+ appId: string;
28
+ action?: string;
29
+ };
30
+ passkey?: {
31
+ rpId: string;
32
+ origin: string;
33
+ };
34
+ onUserResolved?: (user: any, provider: string, raw: any) => Promise<any> | any;
35
+ }
36
+ interface TokenExchangePayload {
37
+ type: 'oauth_code' | 'world_id_proof' | 'passkey_assertion' | 'web3_signature';
38
+ provider?: string;
39
+ code?: string;
40
+ redirectUri?: string;
41
+ state?: string;
42
+ codeVerifier?: string;
43
+ proof?: any;
44
+ action?: string;
45
+ signal?: string;
46
+ assertion?: any;
47
+ challenge?: string;
48
+ address?: string;
49
+ signature?: string;
50
+ message?: string;
51
+ chainId?: number;
52
+ }
53
+ interface TokenExchangeResponse {
54
+ accessToken: string;
55
+ refreshToken?: string;
56
+ expiresIn: number;
57
+ tokenType: string;
58
+ user: {
59
+ id: string;
60
+ name?: string;
61
+ email?: string;
62
+ avatar?: string;
63
+ roles?: string[];
64
+ permissions?: string[];
65
+ [key: string]: any;
66
+ };
67
+ raw?: any;
68
+ }
69
+
70
+ declare class JwtServerService {
71
+ private config;
72
+ constructor(config: JwtServerConfig);
73
+ sign(payload: Record<string, any>, customExpiresIn?: number): string;
74
+ verify(token: string): any | null;
75
+ }
76
+
77
+ declare class OAuthExchanger {
78
+ private configs;
79
+ constructor(configs?: Record<string, OAuthProviderServerConfig>);
80
+ exchangeCode(providerName: string, code: string, options?: {
81
+ redirectUri?: string;
82
+ codeVerifier?: string;
83
+ state?: string;
84
+ }): Promise<{
85
+ rawToken: any;
86
+ profile: any;
87
+ }>;
88
+ private normalizeProfile;
89
+ }
90
+
91
+ /**
92
+ * Server-side verifiers for Web3 SIWE, World ID, and Passkey WebAuthn
93
+ */
94
+ interface SiweParsedMessage {
95
+ domain: string;
96
+ address: string;
97
+ statement?: string;
98
+ uri: string;
99
+ version: string;
100
+ chainId: number;
101
+ nonce: string;
102
+ issuedAt: string;
103
+ expirationTime?: string;
104
+ }
105
+ declare function parseSiweMessage(message: string): SiweParsedMessage | null;
106
+ declare function verifyWorldIdProof(appId: string, action: string, proofPayload: any): Promise<{
107
+ success: boolean;
108
+ nullifierHash?: string;
109
+ error?: string;
110
+ }>;
111
+ declare function verifyPasskeyAssertionFormat(assertion: any, expectedChallenge?: string): {
112
+ success: boolean;
113
+ userHandle?: string;
114
+ error?: string;
115
+ };
116
+
117
+ declare class IsaAuthServer {
118
+ private config;
119
+ private jwtService;
120
+ private oauthExchanger;
121
+ constructor(config: ServerAuthConfig);
122
+ handleExchange(payload: TokenExchangePayload): Promise<TokenExchangeResponse>;
123
+ verifyToken(token: string): any | null;
124
+ }
125
+
126
+ declare function createExpressHandler(server: IsaAuthServer): (req: any, res: any) => Promise<any>;
127
+ declare function createExpressAuthMiddleware(server: IsaAuthServer): (req: any, res: any, next: () => void) => any;
128
+
129
+ /**
130
+ * Next.js Pages Router API Handler:
131
+ * Usage:
132
+ * // pages/api/auth/exchange.ts
133
+ * export default createNextApiHandler(authServer);
134
+ */
135
+ declare function createNextApiHandler(server: IsaAuthServer): (req: any, res: any) => Promise<any>;
136
+ /**
137
+ * Next.js App Router Route Handler:
138
+ * Usage:
139
+ * // app/api/auth/exchange/route.ts
140
+ * export const POST = createNextRouteHandler(authServer);
141
+ */
142
+ declare function createNextRouteHandler(server: IsaAuthServer): (request: Request) => Promise<Response>;
143
+
144
+ export { IsaAuthServer, type JwtServerConfig, JwtServerService, OAuthExchanger, type OAuthProviderServerConfig, type ServerAuthConfig, type SiweParsedMessage, type TokenExchangePayload, type TokenExchangeResponse, createExpressAuthMiddleware, createExpressHandler, createNextApiHandler, createNextRouteHandler, parseSiweMessage, verifyPasskeyAssertionFormat, verifyWorldIdProof };