Skip to content

Commit

Permalink
api: Test oauth things
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Oct 28, 2020
1 parent 5d952ff commit 0030814
Show file tree
Hide file tree
Showing 4 changed files with 1,295 additions and 169 deletions.
2 changes: 2 additions & 0 deletions api/.env.example
@@ -0,0 +1,2 @@
TWITTER_API_KEY="<your twitter app key>"
TWITTER_API_SECRET="<your twitter app secret>"
38 changes: 16 additions & 22 deletions api/twitter-auth.ts
@@ -1,26 +1,20 @@
import {NowRequest, NowResponse} from '@vercel/node';
import {OAuth, oauth1tokenCallback} from 'oauth';

export default (request: NowRequest, response: NowResponse) => {
// var oauth = new OAuth.OAuth(
// 'https://api.twitter.com/oauth/request_token',
// 'https://api.twitter.com/oauth/access_token',
// 'your application consumer key',
// 'your application secret',
// '1.0A',
// null,
// 'HMAC-SHA1'
// );
// oauth.get(
// 'https://api.twitter.com/1.1/trends/place.json?id=23424977',
// 'your user token for this app', //test user token
// 'your user secret for this app', //test user secret
// function (e, data, res){
// if (e) console.error(e);
// console.log(require('util').inspect(data));
// done();
// });
// });
export default async (request: NowRequest, response: NowResponse) => {
var oauth = new OAuth(
'https://api.twitter.com/oauth/request_token',
'https://api.twitter.com/oauth/access_token',
process.env['TWITTER_API_KEY'],
process.env['TWITTER_API_SECRET'],
'1.0A',
null,
'HMAC-SHA1'
);

const {name = 'World'} = request.query;
response.status(200).json(process.env);
const test = await new Promise<Parameters<oauth1tokenCallback>>(resolve =>
oauth.getOAuthRequestToken((...data) => resolve(data))
);

response.status(200).json(test);
};
5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -81,6 +81,7 @@
"@types/node-fetch": "^2.5.7",
"@types/node-gzip": "^1.1.0",
"@types/node-static": "^0.7.5",
"@types/oauth": "^0.9.1",
"@types/object-path": "^0.11.0",
"@types/react": "^16.9.49",
"@types/react-dom": "^16.8.4",
Expand All @@ -95,6 +96,7 @@
"@types/webpack-dev-server": "^3.10.1",
"@types/webpack-env": "^1.13.3",
"@types/webpack-merge": "^4.1.5",
"@vercel/node": "^1.8.4",
"babel-loader": "^8.0.6",
"connect": "^3.7.0",
"cross-env": "^7.0.2",
Expand All @@ -116,10 +118,13 @@
"mobx-react": "^6.2.2",
"mobx-utils": "^5.5.7",
"module-alias": "^2.2.2",
"next": "^10.0.0",
"node-fetch": "^2.6.1",
"node-gzip": "^1.1.2",
"node-static": "^0.7.11",
"noop2": "^2.0.0",
"oauth": "^0.9.15",
"oauth-electron-twitter": "^1.0.109",
"prolink-connect": "0.2.0-prerelease.12",
"public-ip": "^4.0.1",
"react": "^16.8.6",
Expand Down

1 comment on commit 0030814

@vercel
Copy link

@vercel vercel bot commented on 0030814 Oct 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.