# Configure OAuth Authentication

To ingest content from Twitter, you must create a Twitter OAuth application to represent the connector.

Twitter Connector supports the following types of OAuth authentication:

- OAuth 2.0
- OAuth 1.0 (with an Access Token and Secret)

OAuth 1.0 (3-legged OAuth) is also supported, but only by the NiFi Ingest connector.

The following table suggests an appropriate authentication method based on the Twitter API that you want to use.

Twitter API | Suggested authentication method
--- | ---
V2 Filtered Stream | OAuth 2.0 "Service Account"
V2 Sampled Stream | OAuth 2.0 "Service Account"
V2 Search (recent) | OAuth 1.0
V2 Search (full archive) | OAuth 2.0 "Service Account"
V2 User Timeline | OAuth 1.0
V1.1 Premium Search | OAuth 2.0 "Service Account"

To create an OAuth application

1. Go to https://developer.twitter.com/en/portal/projects-and-apps.

2. Create a new app.

   NOTE: To use the Twitter version 2 API, you must create an app within a project, or create a standalone app and then add it to a project. A standalone app can use only the Twitter version 1.1 APIs.

   1. Click Create App.
   2. Type a name for the new app and click Next.
   3. Make a note of the API key, the API secret key, and the bearer token.

3. Click App Settings.

   'Read Only' permission (the default) is sufficient for the connector.

4. (OAuth 1.0 only) Choose whether to use 3-legged OAuth. This allows the connector to obtain the access token and access token secret but is supported only by the NiFi Ingest connector. If you want to use the standard connector, or do not enable 3-legged OAuth, then you must provide the access token and access token secret when you configure the connector.

   - To use 3-legged OAuth (NiFi connector only)

     1. In the Authentication settings area, click Edit.
     2. Enable 3-legged OAuth.

     3. In the Callback URLs box, type your redirect URL.

        TIP: The redirect URL must match the URL shown in the advanced configuration dialog of the NiFi processor. (In the NiFi web interface, right-click the processor and click Configure. Then click ADVANCED. You can find the redirect URL on the OAUTH SETUP tab).

     4. Click Save.

   - To obtain an access token and secret

     1. Click the Keys and tokens tab.
     2. Next to "Access token and Secret", click Generate and make a note of the values.

After creating the OAuth application you can configure the connector.

To configure the connector

- To configure the NiFi Ingest connector

  1. In the NiFi web interface, right-click the processor and click Configure.
  2. Click ADVANCED, and complete the guided setup wizard.
  3. Click the OAUTH SETUP tab.

  4. Click one of the following tabs. If you are unsure which authentication method to use, see the table above.

     - To authenticate using OAuth 2.0, click the Service Account tab.
     - To authenticate using OAuth 1.0 after enabling 3-legged OAuth, click the Single User tab.
     - To authenticate using OAuth 1.0 without enabling 3-legged OAuth, click the Single User by Access Token tab.
  5. Enter the information requested in the dialog (such as the API key and API secret key), and then click SUBMIT.

- To configure the standard connector for OAuth 2.0

  1. Open the folder where you installed the connector.
  2. Open the file `oauth_tool.cfg` in a text editor.

  3. In the `[Default]` section, set any SSL or proxy settings that are required to access the repository:

     `SSLMethod` | The version of SSL/TLS to use.
     `ProxyHost` | The host name or IP address of the proxy server to use.
     `ProxyPort` | The port of the proxy server to use.

     For example:

         SSLMethod=NEGOTIATE
         ProxyHost=10.0.0.1
         ProxyPort=8080

  4. In the `[OAuthTool_service]` section, set the following parameters:

     `AppKey` | The API key that you obtained when you set up the OAuth application.
     `AppSecret` | The API secret key that you obtained when you set up the OAuth application.

     Do not modify the other parameters in this section.

  5. Open a command-line window and run the following command.

     `oauth_tool.exe oauth_tool.cfg OAuthTool_service`

     The OAuth tool generates the files `oauth.cfg` and `oauth2_sites.bin`. When you configure the connector, import the parameters from `oauth.cfg` into your task configuration. For example:

         [MyTask] < "oauth.cfg" [OAUTH]

     For more information about including parameters from another file, see Include an External Configuration File.

- To configure the standard connector for OAuth 1.0, use the information that you obtained when creating the OAuth application to set the following parameters in your task configuration.

  `AppKey` | The API key.
  `AppSecret` | The API secret key.
  `AccessToken` | The access token.
  `AccessTokenSecret` | The access token secret.

For information about how to set up a task to retrieve data from Twitter, see the following topics:

- Retrieve Information from a Filtered Stream
- Retrieve Information from a Sampled Stream
- Retrieve Information from a Search
- Retrieve Information from a User's Timeline

_FT_HTML5_bannerTitle.htm