@@ -5,131 +5,131 @@ const PORT = 4000;
55
66// Simple in-memory account storage
77const accounts = {
8- "test-user" : {
9- accountId : "test-user" ,
10- 11- email_verified : true ,
12- name : "Test User" ,
13- } ,
8+ "test-user" : {
9+ accountId : "test-user" ,
10+ 11+ email_verified : true ,
12+ name : "Test User" ,
13+ } ,
1414} ;
1515
1616// Configuration
1717const configuration = {
18- clients : [
19- {
20- client_id : "better-auth-dev" ,
21- client_secret : "dev-secret-change-in-production" ,
22- redirect_uris : [
23- // Better Auth genericOAuth uses /oauth2/callback/:providerId
24- "http://localhost:3000/api/auth/oauth2/callback/oidc" ,
25- "http://localhost:3001/api/auth/oauth2/callback/oidc" ,
26- "http://localhost:3002/api/auth/oauth2/callback/oidc" ,
27- "http://localhost:3003/api/auth/oauth2/callback/oidc" ,
28- ] ,
29- response_types : [ "code" ] ,
30- grant_types : [ "authorization_code" , "refresh_token" ] ,
31- token_endpoint_auth_method : "client_secret_post" ,
32- } ,
33- ] ,
34- cookies : {
35- keys : [ "some-secret-key-for-dev" ] ,
36- } ,
37- findAccount : async ( ctx , id ) => {
38- const account = accounts [ id ] ;
39- if ( ! account ) return undefined ;
18+ clients : [
19+ {
20+ client_id : "better-auth-dev" ,
21+ client_secret : "dev-secret-change-in-production" ,
22+ redirect_uris : [
23+ // Better Auth genericOAuth uses /oauth2/callback/:providerId
24+ "http://localhost:3000/api/auth/oauth2/callback/oidc" ,
25+ "http://localhost:3001/api/auth/oauth2/callback/oidc" ,
26+ "http://localhost:3002/api/auth/oauth2/callback/oidc" ,
27+ "http://localhost:3003/api/auth/oauth2/callback/oidc" ,
28+ ] ,
29+ response_types : [ "code" ] ,
30+ grant_types : [ "authorization_code" , "refresh_token" ] ,
31+ token_endpoint_auth_method : "client_secret_post" ,
32+ } ,
33+ ] ,
34+ cookies : {
35+ keys : [ "some-secret-key-for-dev" ] ,
36+ } ,
37+ findAccount : async ( ctx , id ) => {
38+ const account = accounts [ id ] ;
39+ if ( ! account ) return undefined ;
4040
41- return {
42- accountId : id ,
43- async claims ( ) {
44- return {
45- sub : id ,
46- email : account . email ,
47- email_verified : account . email_verified ,
48- name : account . name ,
49- } ;
50- } ,
51- } ;
52- } ,
53- // Simple interaction - auto-login for dev
54- interactions : {
55- url ( ctx , interaction ) {
56- return `/interaction/${ interaction . uid } ` ;
57- } ,
58- } ,
59- features : {
60- devInteractions : { enabled : true } , // Enable dev interactions for easy testing
61- } ,
62- claims : {
63- email : [ "email" , "email_verified" ] ,
64- profile : [ "name" ] ,
65- } ,
66- ttl : {
67- AccessToken : 3600 , // 1 hour
68- RefreshToken : 86400 * 30 , // 30 days
69- } ,
41+ return {
42+ accountId : id ,
43+ async claims ( ) {
44+ return {
45+ sub : id ,
46+ email : account . email ,
47+ email_verified : account . email_verified ,
48+ name : account . name ,
49+ } ;
50+ } ,
51+ } ;
52+ } ,
53+ // Simple interaction - auto-login for dev
54+ interactions : {
55+ url ( ctx , interaction ) {
56+ return `/interaction/${ interaction . uid } ` ;
57+ } ,
58+ } ,
59+ features : {
60+ devInteractions : { enabled : true } , // Enable dev interactions for easy testing
61+ } ,
62+ claims : {
63+ email : [ "email" , "email_verified" ] ,
64+ profile : [ "name" ] ,
65+ } ,
66+ ttl : {
67+ AccessToken : 3600 , // 1 hour
68+ RefreshToken : 86400 * 30 , // 30 days
69+ } ,
7070} ;
7171
7272const oidc = new Provider ( ISSUER , configuration ) ;
7373
7474// Simple interaction endpoint for dev - auto-login as test-user
7575oidc . use ( async ( ctx , next ) => {
76- if ( ctx . path . startsWith ( "/interaction/" ) ) {
77- const uid = ctx . path . split ( "/" ) [ 2 ] ;
78- const interaction = await oidc . interactionDetails ( ctx . req , ctx . res ) ;
76+ if ( ctx . path . startsWith ( "/interaction/" ) ) {
77+ const uid = ctx . path . split ( "/" ) [ 2 ] ;
78+ const interaction = await oidc . interactionDetails ( ctx . req , ctx . res ) ;
7979
80- if ( interaction . prompt . name === "login" ) {
81- // Auto-login as test-user for dev
82- await oidc . interactionFinished (
83- ctx . req ,
84- ctx . res ,
85- {
86- login : {
87- accountId : "test-user" ,
88- } ,
89- } ,
90- { mergeWithLastSubmission : false } ,
91- ) ;
92- return ;
93- }
80+ if ( interaction . prompt . name === "login" ) {
81+ // Auto-login as test-user for dev
82+ await oidc . interactionFinished (
83+ ctx . req ,
84+ ctx . res ,
85+ {
86+ login : {
87+ accountId : "test-user" ,
88+ } ,
89+ } ,
90+ { mergeWithLastSubmission : false } ,
91+ ) ;
92+ return ;
93+ }
9494
95- if ( interaction . prompt . name === "consent" ) {
96- // Auto-consent for dev
97- const grant = new oidc . Grant ( {
98- accountId : interaction . session . accountId ,
99- clientId : interaction . params . client_id ,
100- } ) ;
95+ if ( interaction . prompt . name === "consent" ) {
96+ // Auto-consent for dev
97+ const grant = new oidc . Grant ( {
98+ accountId : interaction . session . accountId ,
99+ clientId : interaction . params . client_id ,
100+ } ) ;
101101
102- grant . addOIDCScope (
103- interaction . params . scope
104- ?. split ( " " )
105- . filter ( ( scope ) => [ "openid" , "email" , "profile" ] . includes ( scope ) )
106- . join ( " " ) || "openid email profile" ,
107- ) ;
102+ grant . addOIDCScope (
103+ interaction . params . scope
104+ ?. split ( " " )
105+ . filter ( ( scope ) => [ "openid" , "email" , "profile" ] . includes ( scope ) )
106+ . join ( " " ) || "openid email profile" ,
107+ ) ;
108108
109- await grant . save ( ) ;
109+ await grant . save ( ) ;
110110
111- await oidc . interactionFinished (
112- ctx . req ,
113- ctx . res ,
114- {
115- consent : {
116- grantId : grant . jti ,
117- } ,
118- } ,
119- { mergeWithLastSubmission : true } ,
120- ) ;
121- return ;
122- }
123- }
124- await next ( ) ;
111+ await oidc . interactionFinished (
112+ ctx . req ,
113+ ctx . res ,
114+ {
115+ consent : {
116+ grantId : grant . jti ,
117+ } ,
118+ } ,
119+ { mergeWithLastSubmission : true } ,
120+ ) ;
121+ return ;
122+ }
123+ }
124+ await next ( ) ;
125125} ) ;
126126
127127oidc . listen ( PORT , ( ) => {
128- console . log ( `🔐 OIDC Provider running at ${ ISSUER } ` ) ;
129- console . log ( `📝 Client ID: better-auth-dev` ) ;
130- console . log ( `🔑 Client Secret: dev-secret-change-in-production` ) ;
131- console . log ( `👤 Test user: [email protected] ` ) ; 132- console . log (
133- `\n⚙️ Update your .env.local with:\nOIDC_CLIENT_ID=better-auth-dev\nOIDC_CLIENT_SECRET=dev-secret-change-in-production\nOIDC_ISSUER_URL=${ ISSUER } ` ,
134- ) ;
128+ console . log ( `🔐 OIDC Provider running at ${ ISSUER } ` ) ;
129+ console . log ( `📝 Client ID: better-auth-dev` ) ;
130+ console . log ( `🔑 Client Secret: dev-secret-change-in-production` ) ;
131+ console . log ( `👤 Test user: [email protected] ` ) ; 132+ console . log (
133+ `\n⚙️ Update your .env.local with:\nOIDC_CLIENT_ID=better-auth-dev\nOIDC_CLIENT_SECRET=dev-secret-change-in-production\nOIDC_ISSUER_URL=${ ISSUER } ` ,
134+ ) ;
135135} ) ;
0 commit comments