mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	using custom header for sync authorization to avoid tripping security proxies
This commit is contained in:
		
							parent
							
								
									fb3d5f25ac
								
							
						
					
					
						commit
						70708b36ef
					
				| @ -224,7 +224,7 @@ function register(app) { | ||||
|     route(GET, '/api/setup/status', [], setupApiRoute.getStatus, apiResultHandler); | ||||
|     route(POST, '/api/setup/new-document', [auth.checkAppNotInitialized], setupApiRoute.setupNewDocument, apiResultHandler); | ||||
|     route(POST, '/api/setup/sync-from-server', [auth.checkAppNotInitialized], setupApiRoute.setupSyncFromServer, apiResultHandler, false); | ||||
|     route(GET, '/api/setup/sync-seed', [auth.checkBasicAuth], setupApiRoute.getSyncSeed, apiResultHandler); | ||||
|     route(GET, '/api/setup/sync-seed', [auth.checkCredentials], setupApiRoute.getSyncSeed, apiResultHandler); | ||||
|     route(POST, '/api/setup/sync-seed', [auth.checkAppNotInitialized], setupApiRoute.saveSyncSeed, apiResultHandler, false); | ||||
| 
 | ||||
|     apiRoute(GET, '/api/sql/schema', sqlRoute.getSchema); | ||||
|  | ||||
| @ -77,8 +77,8 @@ function reject(req, res, message) { | ||||
|     res.status(401).send(message); | ||||
| } | ||||
| 
 | ||||
| function checkBasicAuth(req, res, next) { | ||||
|     const header = req.headers.authorization || ''; | ||||
| function checkCredentials(req, res, next) { | ||||
|     const header = req.headers['trilium-cred'] || ''; | ||||
|     const token = header.split(/\s+/).pop() || ''; | ||||
|     const auth = new Buffer.from(token, 'base64').toString(); | ||||
|     const [username, password] = auth.split(/:/); | ||||
| @ -100,5 +100,5 @@ module.exports = { | ||||
|     checkAppNotInitialized, | ||||
|     checkApiAuthOrElectron, | ||||
|     checkToken, | ||||
|     checkBasicAuth | ||||
|     checkCredentials | ||||
| }; | ||||
|  | ||||
| @ -70,9 +70,9 @@ async function setupSyncFromSyncServer(syncServerHost, syncProxy, username, pass | ||||
|         const resp = await request.exec({ | ||||
|             method: 'get', | ||||
|             url: syncServerHost + '/api/setup/sync-seed', | ||||
|             auth: { | ||||
|                 'user': username, | ||||
|                 'pass': password | ||||
|             headers: { | ||||
|                 // not using Authorization header because some proxy servers will filter it out
 | ||||
|                 'trilium-cred': Buffer.from(username + ':' + password).toString('base64') | ||||
|             }, | ||||
|             proxy: syncProxy, | ||||
|             timeout: 30000 // seed request should not take long
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam