Skip to content

Commit

Permalink
Added oauth/authenticate parameters (force_login and screen_name) (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
esthedebeste authored Aug 20, 2021
1 parent a25bf3f commit 6eacc25
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 14 additions & 6 deletions src/client/readonly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,15 @@ export default class TwitterApiReadOnly extends TwitterApiBase {
return this._currentUser;
}

return this._currentUser = await this.v1.verifyCredentials();
return (this._currentUser = await this.v1.verifyCredentials());
}


/* Shortcuts to endpoints */

public search(what: string, options?: Partial<Tweetv2SearchParams>) {
return this.v2.search(what, options);
}


/* Authentification */

/**
Expand All @@ -71,14 +69,24 @@ export default class TwitterApiReadOnly extends TwitterApiBase {
* // Save tokenRequest.oauth_token_secret somewhere, it will be needed for next auth step.
* ```
*/
public async generateAuthLink(oauth_callback = 'oob', { authAccessType, linkMode = 'authenticate' }: Partial<RequestTokenArgs> = {}) {
public async generateAuthLink(
oauth_callback = 'oob',
{
authAccessType,
linkMode = 'authenticate',
forceLogin,
screenName,
}: Partial<RequestTokenArgs> = {}
) {
const oauth_result = await this.post<RequestTokenResult>(
'https://api.twitter.com/oauth/request_token',
{ oauth_callback, x_auth_access_type: authAccessType }
);

let url = `https://api.twitter.com/oauth/${linkMode}?oauth_token=${encodeURIComponent(oauth_result.oauth_token)}`;
if (forceLogin != null) url += `&force_login=${forceLogin}`;
if (screenName != null) url += `&screen_name=${screenName}`;
return {
url: `https://api.twitter.com/oauth/${linkMode}?oauth_token=${encodeURIComponent(oauth_result.oauth_token)}`,
url,
...oauth_result,
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/auth.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type TwitterApi from '../client';
export interface RequestTokenArgs {
authAccessType: 'read' | 'write';
linkMode: 'authenticate' | 'authorize';
forceLogin: boolean;
screenName: string;
}

export interface RequestTokenResult {
Expand Down

0 comments on commit 6eacc25

Please sign in to comment.