This repository was archived by the owner on Feb 10, 2025. It is now read-only.
Commit 2ef3971 1 parent 6c57b4e commit 2ef3971 Copy full SHA for 2ef3971
File tree 7 files changed +141
-8
lines changed
7 files changed +141
-8
lines changed Original file line number Diff line number Diff line change 17
17
"types" : " tsc --noEmit --incremental" ,
18
18
"verify" : " yarn lint && yarn types" ,
19
19
"reset-password" : " node src/scripts/reset-password.js" ,
20
+ "enable-openid" : " node src/scripts/enable-openid.js" ,
21
+ "disable-openid" : " node src/scripts/disable-openid.js" ,
20
22
"health-check" : " node src/scripts/health-check.js"
21
23
},
22
24
"dependencies" : {
Original file line number Diff line number Diff line change @@ -169,9 +169,25 @@ export async function disableOpenID(loginSettings) {
169
169
return { error } ;
170
170
}
171
171
172
- getAccountDb ( ) . mutate ( 'DELETE FROM sessions' ) ;
173
- getAccountDb ( ) . mutate ( 'DELETE FROM users WHERE user_name <> ?' , [ '' ] ) ;
174
- getAccountDb ( ) . mutate ( 'DELETE FROM auth WHERE method = ?' , [ 'openid' ] ) ;
172
+ try {
173
+ accountDb . transaction ( ( ) => {
174
+ accountDb . mutate ( 'DELETE FROM sessions' ) ;
175
+ accountDb . mutate (
176
+ `DELETE FROM user_access
177
+ WHERE user_access.user_id IN (
178
+ SELECT users.id
179
+ FROM users
180
+ WHERE users.user_name <> ?
181
+ );` ,
182
+ [ '' ] ,
183
+ ) ;
184
+ accountDb . mutate ( 'DELETE FROM users WHERE user_name <> ?' , [ '' ] ) ;
185
+ accountDb . mutate ( 'DELETE FROM auth WHERE method = ?' , [ 'openid' ] ) ;
186
+ } ) ;
187
+ } catch ( err ) {
188
+ console . error ( 'Error cleaning up openid information:' , err ) ;
189
+ return { error : 'database-error' } ;
190
+ }
175
191
}
176
192
177
193
export function getSession ( token ) {
Original file line number Diff line number Diff line change @@ -170,11 +170,22 @@ export async function loginWithOpenIdFinalize(body) {
170
170
let { code_verifier, return_url } = pendingRequest ;
171
171
172
172
try {
173
- const params = { code : body . code , state : body . state } ;
174
- let tokenSet = await client . callback ( client . redirect_uris [ 0 ] , params , {
175
- code_verifier,
176
- state : body . state ,
177
- } ) ;
173
+ let tokenSet = null ;
174
+
175
+ if ( ! config . authMethod || config . authMethod === 'openid' ) {
176
+ const params = { code : body . code , state : body . state } ;
177
+ tokenSet = await client . callback ( client . redirect_uris [ 0 ] , params , {
178
+ code_verifier,
179
+ state : body . state ,
180
+ } ) ;
181
+ } else {
182
+ tokenSet = await client . grant ( {
183
+ grant_type : 'authorization_code' ,
184
+ code : body . code ,
185
+ redirect_uri : client . redirect_uris [ 0 ] ,
186
+ code_verifier,
187
+ } ) ;
188
+ }
178
189
const userInfo = await client . userinfo ( tokenSet . access_token ) ;
179
190
const identity =
180
191
userInfo . preferred_username ??
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ export interface Config {
32
32
client_id : string ;
33
33
client_secret : string ;
34
34
server_hostname : string ;
35
+ authMethod ?: 'openid' | 'oauth2' ;
35
36
} ;
36
37
multiuser : boolean ;
37
38
token_expiration ?: 'never' | 'openid-provider' | number ;
Original file line number Diff line number Diff line change
1
+ import {
2
+ disableOpenID ,
3
+ getActiveLoginMethod ,
4
+ needsBootstrap ,
5
+ } from '../account-db.js' ;
6
+ import { promptPassword } from '../util/prompt.js' ;
7
+
8
+ if ( needsBootstrap ( ) ) {
9
+ console . log ( 'System needs to be bootstrapped first. OpenID is not enabled.' ) ;
10
+
11
+ process . exit ( 1 ) ;
12
+ } else {
13
+ console . log ( 'To disable OpenID, you have to enter your server password:' ) ;
14
+ try {
15
+ const loginMethod = getActiveLoginMethod ( ) ;
16
+ console . log ( `Current login method: ${ loginMethod } ` ) ;
17
+
18
+ if ( loginMethod === 'password' ) {
19
+ console . log ( 'OpenID already disabled.' ) ;
20
+ process . exit ( 0 ) ;
21
+ }
22
+
23
+ const password = await promptPassword ( ) ;
24
+ const { error } = ( await disableOpenID ( { password } ) ) || { } ;
25
+
26
+ if ( error ) {
27
+ console . log ( 'Error disabling OpenID:' , error ) ;
28
+ console . log (
29
+ 'Please report this as an issue: https://github.com/actualbudget/actual-server/issues' ,
30
+ ) ;
31
+ process . exit ( 2 ) ;
32
+ }
33
+ console . log ( 'OpenID disabled!' ) ;
34
+ console . log (
35
+ 'Note: you will need to log in with the password on any browsers or devices that are currently logged in.' ,
36
+ ) ;
37
+ } catch ( err ) {
38
+ console . log ( 'Unexpected error:' , err ) ;
39
+ console . log (
40
+ 'Please report this as an issue: https://github.com/actualbudget/actual-server/issues' ,
41
+ ) ;
42
+ process . exit ( 2 ) ;
43
+ }
44
+ }
Original file line number Diff line number Diff line change
1
+ import {
2
+ enableOpenID ,
3
+ getActiveLoginMethod ,
4
+ needsBootstrap ,
5
+ } from '../account-db.js' ;
6
+ import finalConfig from '../load-config.js' ;
7
+
8
+ if ( needsBootstrap ( ) ) {
9
+ console . log (
10
+ 'It looks like you don’t have a password set yet. Password is the fallback authentication method when using OpenID. Execute the command reset-password before using this command!' ,
11
+ ) ;
12
+
13
+ process . exit ( 1 ) ;
14
+ } else {
15
+ console . log ( 'Enabling openid based on Environment variables or config.json' ) ;
16
+ try {
17
+ const loginMethod = getActiveLoginMethod ( ) ;
18
+ console . log ( `Current login method: ${ loginMethod } ` ) ;
19
+
20
+ if ( loginMethod === 'openid' ) {
21
+ console . log ( 'OpenID already enabled.' ) ;
22
+ process . exit ( 0 ) ;
23
+ }
24
+ const { error } = ( await enableOpenID ( finalConfig ) ) || { } ;
25
+
26
+ if ( error ) {
27
+ console . log ( 'Error enabling openid:' , error ) ;
28
+ if ( error === 'invalid-login-settings' ) {
29
+ console . log (
30
+ 'Error configuring OpenID. Please verify that the configuration file or environment variables are correct.' ,
31
+ ) ;
32
+
33
+ process . exit ( 1 ) ;
34
+ } else {
35
+ console . log (
36
+ 'Please report this as an issue: https://github.com/actualbudget/actual-server/issues' ,
37
+ ) ;
38
+
39
+ process . exit ( 2 ) ;
40
+ }
41
+ }
42
+ console . log ( 'OpenID enabled!' ) ;
43
+ console . log (
44
+ 'Note: The first user to login with OpenID will be the owner of the server.' ,
45
+ ) ;
46
+ } catch ( err ) {
47
+ console . log ( 'Unexpected error:' , err ) ;
48
+ console . log (
49
+ 'Please report this as an issue: https://github.com/actualbudget/actual-server/issues' ,
50
+ ) ;
51
+ process . exit ( 2 ) ;
52
+ }
53
+ }
Original file line number Diff line number Diff line change
1
+ ---
2
+ category : Enhancements
3
+ authors : [lelemm]
4
+ ---
5
+
6
+ Commands to enable/disable OpenID from console. Also, enabling to login with oauth2 (for github).
You can’t perform that action at this time.
0 commit comments