1.0.1 • Published 4 years ago

react-twitter-oauth v1.0.1

Weekly downloads
26
License
MIT
Repository
github
Last release
4 years ago

react-twitter-oauth

npm npm bundle size npm

React component for a simple OAuth Twitter integration. Forked from (https://github.com/alexandrtovmach/react-twitter-login)

🚀 Get Started

Follow these steps to start using React Twitter Oauth:

  1. Installation

    # with npm
    npm i react-twitter-oauth
    
    # with yarn
    yarn add react-twitter-oauth
  2. Import and configure component.

    This component should be rendered on route that match with one of whitelisted callback URLs of your Twitter app.

    import React from "react";
    import TwitterLogin from "react-twitter-oauth";
    
    export default (props) => {
      const authHandler = (err, data) => {
        console.log(err, data);
      };
    
      return (
        <TwitterLogin
          authCallback={authHandler}
          consumerKey={CONSUMER_KEY}
          consumerSecret={CONSUMER_SECRET}
          requestTokenUrl={REQUEST_TOKEN_API_ENDPOINT}
          accessTokenUrl={ACCESS_TOKEN_API_ENDPOINT}
        />
      );
    };
  3. REQUEST_TOKEN_API_ENDPOINT get object and send to https://api.twitter.com/oauth/request_token

    {   
       "oauth_callback": "https://[oauth_callback]",
       "oauth_consumer_key": "CONSUMER_KEY",
       "oauth_nonce": "oauth nonce generated from component",
       "oauth_signature": "oauth signature generated from component",
       "oauth_signature_method": "HMAC-SHA1",
       "oauth_timestamp": "oauth timestamp generated from component",
       "oauth_version": "1.0"
    }

    then the response should be of this kind

    {   
        "data": {
            "oauth_callback_confirmed": "true",
            "oauth_token": "oauth token from twitter",
            "oauth_token_secret": "oauth token secret from twitter"
        }
    }
  4. ACCESS_TOKEN_API_ENDPOINT get object and send to https://api.twitter.com/oauth/access_token

    {   
       "oauth_consumer_key": "CONSUMER_KEY",
       "oauth_nonce": "oauth nonce generated from component",
       "oauth_signature": "oauth signature generated from component",
       "oauth_signature_method": "HMAC-SHA1",
       "oauth_token": "oauth token generated from twitter",
       "oauth_verifier": "oauth verifier generated from component",
       "oauth_timestamp": "oauth timestamp generated from component",
       "oauth_version": "1.0"
    }

    the server response must contain the following data

    {   
        "data": {
            "oauth_token": "true",
            "oauth_token_secret": "oauth token secret from twitter",
        }
    }
  5. Find more info about keys and Twitter developer apps in official docs.

📖 API

PropertyTypeDefaultDescription
authCallbackfunctionrequiredCallback function which takes two arguments (error, authData)
consumerKeystringrequiredConsumer API Key of your Twitter developer app (not Access Token)
consumerSecretstringrequiredConsumer API Secret of your Twitter developer app (not Access Token Secret)
requestTokenUrlstringrequiredApi endpoint will be used to get request token
accessTokenUrlstringrequiredApi endpoint will be used to get access token
buttonThemeenum("light", "light_short", "dark", "dark_short")"light"Button style theme, that based on Twitter Brand Design
classNamestring""Custom class name
childrenReact.Component""Provide any component as a "children" prop to use custom button

📝 License

MIT

1.1.1

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.1.2

4 years ago

1.2.3

4 years ago