wip
This commit is contained in:
		
							parent
							
								
									6f7cf99f19
								
							
						
					
					
						commit
						42268f0fd4
					
				
					 4 changed files with 37 additions and 22 deletions
				
			
		|  | @ -65,6 +65,7 @@ | |||
|     "@types/websocket": "0.0.32", | ||||
|     "accesses": "1.2.0", | ||||
|     "argv": "0.0.2", | ||||
|     "autwh": "0.0.0", | ||||
|     "babel-core": "6.22.1", | ||||
|     "babel-polyfill": "6.20.0", | ||||
|     "babel-preset-es2015": "6.22.0", | ||||
|  |  | |||
|  | @ -28,6 +28,9 @@ app.use(compression()); | |||
|  */ | ||||
| app.use((req, res, next) => { | ||||
| 	res.header('X-Frame-Options', 'DENY'); | ||||
| 
 | ||||
| 	res.locals.user = (req.headers['cookie'].match(/i=(!\w+)/) || [null, null])[1]; | ||||
| 
 | ||||
| 	next(); | ||||
| }); | ||||
| 
 | ||||
|  | @ -48,7 +51,7 @@ app.get(/\/api:meta/, require('./meta')); | |||
| app.get(/\/api:url/,  require('./service/url-preview')); | ||||
| app.post(/\/api:rss/, require('./service/rss-proxy')); | ||||
| 
 | ||||
| app.get(/\/connect:twitter/, require('./service/twitter/begin')); | ||||
| require('./service/twitter')(app); | ||||
| 
 | ||||
| /** | ||||
|  * Subdomain | ||||
|  |  | |||
							
								
								
									
										32
									
								
								src/web/service/twitter.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/web/service/twitter.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,32 @@ | |||
| import * as express from 'express'; | ||||
| //import * as Twitter from 'twitter';
 | ||||
| //const Twitter = require('twitter');
 | ||||
| import autwh from 'autwh'; | ||||
| import redis from '../../db/redis'; | ||||
| import config from '../../conf'; | ||||
| 
 | ||||
| module.exports = (app: express.Application) => { | ||||
| 	if (config.twitter == null) return; | ||||
| 
 | ||||
| 	const twAuth = autwh({ | ||||
| 		consumerKey: config.twitter.consumer_key, | ||||
| 		consumerSecret: config.twitter.consumer_secret, | ||||
| 		callbackUrl: config.url + '/tw/cb' | ||||
| 	}); | ||||
| 
 | ||||
| 	app.get('/twitter:connect', async (req, res): Promise<any> => { | ||||
| 		if (res.locals.user == null) return res.send('plz signin'); | ||||
| 		const ctx = await twAuth.begin(); | ||||
| 		redis.set(res.locals.user, JSON.stringify(ctx)); | ||||
| 		res.redirect(ctx.url); | ||||
| 	}); | ||||
| 
 | ||||
| 	app.get('/twitter/callback', (req, res): any => { | ||||
| 		if (res.locals.user == null) return res.send('plz signin'); | ||||
| 		redis.get(res.locals.user, async (_, ctx) => { | ||||
| 			const tokens = await twAuth.done(JSON.parse(ctx), req.query.oauth_verifier); | ||||
| 			console.log(tokens); | ||||
| 			res.send('Authorized!'); | ||||
| 		}) | ||||
| 	}); | ||||
| }; | ||||
|  | @ -1,21 +0,0 @@ | |||
| import * as express from 'express'; | ||||
| //import * as Twitter from 'twitter';
 | ||||
| const Twitter = require('twitter'); | ||||
| import config from '../../../conf'; | ||||
| 
 | ||||
| module.exports = (req: express.Request, res: express.Response) => { | ||||
| 	if (config.twitter) { | ||||
| 		const client = new Twitter({ | ||||
| 			consumer_key: config.twitter.consumer_key, | ||||
| 			consumer_secret: config.twitter.consumer_secret | ||||
| 		}); | ||||
| 
 | ||||
| 		client.post('oauth/request_token', { | ||||
| 			oauth_callback: config.url + '/tw/cb' | ||||
| 		}, (x, y, z) => { | ||||
| 			console.log(x); | ||||
| 			console.log(y); | ||||
| 			console.log(z); | ||||
| 		}); | ||||
| 	} | ||||
| }; | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue