-
-
Notifications
You must be signed in to change notification settings - Fork 142
/
accounts-oauth-twitter.ts
52 lines (46 loc) · 1.49 KB
/
accounts-oauth-twitter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { OAuth } from 'oauth';
import { type Configuration } from './types/configuration';
import { type OAuthProvider, type OAuthUser } from '@accounts/oauth';
export class AccountsOAuthTwitter implements OAuthProvider {
private config: Configuration;
private oauth: any;
public getRegistrationPayload?: (oauthUser: OAuthUser) => Promise<any>;
constructor(config: Configuration) {
this.config = config;
this.oauth = new OAuth(
'https://twitter.com/oauth/request_token',
'https://twitter.com/oauth/access_token',
this.config.key,
this.config.secret,
'1.0A',
null,
'HMAC-SHA1'
);
this.getRegistrationPayload = config.getRegistrationPayload;
}
public authenticate(params: any): Promise<OAuthUser> {
return new Promise((resolve, reject) => {
this.oauth.get(
'https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true',
params.access_token,
params.access_token_secret,
(err: any, data: any) => {
if (err) {
reject(err);
} else {
data = JSON.parse(data);
const user = {
id: data.id_str,
screenName: data.screen_name,
profilePicture: data.profile_image_url_https,
email: data.email,
accessToken: params.access_token,
accessTokenSecret: params.access_token_secret,
};
resolve(user);
}
}
);
});
}
}