Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added generic connector for Twitter API #1285

Merged
merged 1 commit into from
Jul 7, 2020

Conversation

mdodell
Copy link
Contributor

@mdodell mdodell commented Jun 24, 2020

What does this PR do?

  • Added a generic connector for Twitter's API for both OAuth 1 and 2

What ticket does this PR close?

Connected to #1264

Checklists

Change log

  • The CHANGELOG has been updated, or
  • This PR does not include user-facing changes and doesn't require a CHANGELOG update

Test coverage

  • This PR includes new unit and integration tests to go with the code changes, or
  • The changes in this PR do not require tests

Documentation

  • This PR does not require updating any documentation, or
  • Docs (e.g. READMEs) were updated in this PR, and/or there is a follow-on issue to update docs

(For releases only) Manual tests

@mdodell mdodell self-assigned this Jun 24, 2020
@mdodell mdodell linked an issue Jun 24, 2020 that may be closed by this pull request
2 tasks
@mdodell
Copy link
Contributor Author

mdodell commented Jun 24, 2020

I am currently having some issues trying to generate a valid request using OAuth1 and Curl. Twitter says in their docs you can make a curl request using OAuth1 like this after creating a Twitter development account:

curl --request POST \
  --url 'https://api.twitter.com/1.1/statuses/update.json?status=Hello%20world' \
  --header 'authorization: OAuth oauth_consumer_key="CONSUMER_API_KEY", oauth_nonce="OAUTH_NONCE", oauth_signature="OAUTH_SIGNATURE", oauth_signature_method="HMAC-SHA1", oauth_timestamp="OAUTH_TIMESTAMP", oauth_token="ACCESS_TOKEN", oauth_version="1.0"' \

However, this request results in {"errors":[{"code":215,"message":"Bad Authentication data."}]}.

When I added --header 'Content-Type: application/x-www-form-urlencoded, it gave back the response {"errors":[{"code":32,"message":"Could not authenticate you."}]}.

I used Postman to generate a request, which gave back a valid result using OAuth1. In Postman, you can export what the request looks like in a variety of languages, including Curl. That exported request looks like this:

 curl --location --request POST 'https://api.twitter.com/1.1/statuses/update.json?status=Hello%20World' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'oauth_consumer_key=<my-consumer-key>' \
--data-urlencode 'oauth_token=<my-token>' \
--data-urlencode 'oauth_signature_method=HMAC-SHA1' \
--data-urlencode 'oauth_timestamp=<time-stamp>' \
--data-urlencode 'oauth_nonce=<randomly-generated-nonce>' \
--data-urlencode 'oauth_version=1.0' \
--data-urlencode 'oauth_signature=<signature>'

This is a valid request. I can't figure out how to make a CURL request using what Twitter provided in their documentation, since the parameters are the same. If there was a way to incorporate these parameters in the Authorization header, we could use the generic HTTP config in Secretless as it currently is.

It looks like this method may need to use query parameters, and may be another use-case of Secretless being able to integrate secure body parameters.


The configuration file for the Splunk Web API can be found at [twitter_secretless.yml](./twitter_secretless.yml).

**Note:** This configuration currently only supports connecting to the Twitter API via OAuth2. An issue can be found here for adding an OAuth1 Connector for
Copy link

Choose a reason for hiding this comment

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

Line length

Twitter.

#### How to use this connector
* Edit the supplied service configuration to get your
Copy link

Choose a reason for hiding this comment

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

Lists should be surrounded by blank lines

#### How to use this connector
* Edit the supplied service configuration to get your
[OAuth token](https://developer.twitter.com/en/docs/basics/authentication/oauth-2-0/bearer-tokens)
* Run secretless with the supplied configuration(s)
Copy link

Choose a reason for hiding this comment

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

Lists should be surrounded by blank lines

<ol>
<li>
Get your
<a href="https://developer.twitter.com/en/apps">
Copy link

Choose a reason for hiding this comment

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

Inline HTML

</li>
<li>
Get an
<a href="https://developer.twitter.com/en/docs/basics/authentication/oauth-2-0/bearer-tokens">
Copy link

Choose a reason for hiding this comment

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

Inline HTML

@mdodell mdodell force-pushed the add-twitter-generic-example branch from 9b21d0f to 8fe254c Compare July 6, 2020 18:23
@mdodell
Copy link
Contributor Author

mdodell commented Jul 6, 2020

Note: An OAuth1 service could not be supported in this PR. There is an outstanding issue for an OAuth1 connector here.


The configuration file for the Splunk Web API can be found at [twitter_secretless.yml](./twitter_secretless.yml).

**Note:** This configuration currently only supports connecting to the Twitter API via OAuth2. An issue can be found
Copy link

Choose a reason for hiding this comment

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

Line length

Copy link
Contributor

Choose a reason for hiding this comment

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

We should try to respect line length limits when possible - I'd break this into two lines

<br />
'https://api.twitter.com/oauth2/token'
</code>
<li>Save the local token from the request into the OSX keychain</li>
Copy link

Choose a reason for hiding this comment

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

Inline HTML

<br />
--data 'grant_type=client_credentials' \
<br />
'https://api.twitter.com/oauth2/token'
Copy link

Choose a reason for hiding this comment

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

Bare URL used

Twitter API key and Secret Key
</a>
</li>
<li>
Copy link

Choose a reason for hiding this comment

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

Bare URL used

Copy link
Contributor

@BradleyBoutcher BradleyBoutcher left a comment

Choose a reason for hiding this comment

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

Looks good! Just a few small things stood out

examples/generic_connector_configs/README.md Outdated Show resolved Hide resolved
examples/generic_connector_configs/README.md Outdated Show resolved Hide resolved

The configuration file for the Splunk Web API can be found at [twitter_secretless.yml](./twitter_secretless.yml).

**Note:** This configuration currently only supports connecting to the Twitter API via OAuth2. An issue can be found
Copy link
Contributor

Choose a reason for hiding this comment

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

We should try to respect line length limits when possible - I'd break this into two lines

@mdodell mdodell force-pushed the add-twitter-generic-example branch from 8fe254c to da0ab23 Compare July 6, 2020 20:32
@@ -23,9 +24,13 @@ If your target uses self-signed certs you will need to follow the
[documented instructions](https://docs.secretless.io/Latest/en/Content/References/connectors/scl_handlers-https.htm#Manageservercertificates) for adding the
target’s CA to Secretless’ trusted certificate pool.


Copy link

Choose a reason for hiding this comment

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

Multiple consecutive blank lines

> Note: The following examples use the [Keychain provider](https://docs.cyberark.com/Product-Doc/OnlineHelp/AAM-DAP/11.3/en/Content/References/providers/scl_keychain.htm?TocPath=Fundamentals%7CSecretless%20Pattern%7CSecret%20Providers%7C_____5).
> Replace the service prefix `service#` with an appropriate service
> or use a different provider as needed.

Copy link

Choose a reason for hiding this comment

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

Blank line inside blockquote

examples/generic_connector_configs/README.md Show resolved Hide resolved
examples/generic_connector_configs/README.md Show resolved Hide resolved
examples/generic_connector_configs/README.md Show resolved Hide resolved
Copy link
Contributor

@BradleyBoutcher BradleyBoutcher left a comment

Choose a reason for hiding this comment

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

One formatting thing and one nit

examples/generic_connector_configs/README.md Outdated Show resolved Hide resolved
examples/generic_connector_configs/README.md Outdated Show resolved Hide resolved
@mdodell mdodell force-pushed the add-twitter-generic-example branch from da0ab23 to 60170ca Compare July 6, 2020 21:53
examples/generic_connector_configs/README.md Show resolved Hide resolved
examples/generic_connector_configs/README.md Show resolved Hide resolved
@@ -127,10 +134,13 @@ depending on if your endpoint requires JSON or URL encoded requests

#### Example Usage
<details>
<summary><b>How to use this connector locally...</b></summary>
<summary><b>Example setup to try this out locally...</b></summary>
Copy link

Choose a reason for hiding this comment

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

Inline HTML

examples/generic_connector_configs/README.md Show resolved Hide resolved
examples/generic_connector_configs/README.md Show resolved Hide resolved
@BradleyBoutcher BradleyBoutcher force-pushed the add-twitter-generic-example branch 2 times, most recently from 73f5a67 to c4b404d Compare July 7, 2020 16:43
@mdodell mdodell force-pushed the add-twitter-generic-example branch 2 times, most recently from 3783a03 to 5e504dc Compare July 7, 2020 17:05
one should be used.

#### How to use this connector
* Get the [Stripe API Key](https://dashboard.stripe.com/apikeys), which can be used as a Bearer token
Copy link

Choose a reason for hiding this comment

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

Line length


#### How to use this connector
* Get the [Stripe API Key](https://dashboard.stripe.com/apikeys), which can be used as a Bearer token
* Get a [connected account](https://stripe.com/docs/connect/authentication) or generate an [idempotency key](https://stripe.com/docs/api/idempotent_requests) if needed
Copy link

Choose a reason for hiding this comment

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

Line length

one should be used.

#### How to use this connector
* Get the [Stripe API Key](https://dashboard.stripe.com/apikeys), which can be used as a Bearer token
Copy link

Choose a reason for hiding this comment

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

Lists should be surrounded by blank lines

examples/generic_connector_configs/README.md Show resolved Hide resolved
examples/generic_connector_configs/README.md Show resolved Hide resolved
@mdodell mdodell marked this pull request as ready for review July 7, 2020 18:07
@mdodell mdodell requested a review from a team as a code owner July 7, 2020 18:07
examples/generic_connector_configs/README.md Show resolved Hide resolved

#### Example Usage
<details>
<summary><b>Example setup to try this out locally</b></summary>
Copy link

Choose a reason for hiding this comment

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

Inline HTML


#### Example Usage
<details>
<summary><b>Example setup to try this out locally</b></summary>
Copy link

Choose a reason for hiding this comment

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

Inline HTML

</code>
<li>
Store the token from your request in your local credential manager so
that it may be retrieved in your <code>secretless.yml</code>
Copy link

Choose a reason for hiding this comment

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

Inline HTML

examples/generic_connector_configs/README.md Show resolved Hide resolved

#### Example Usage
<details>
<summary><b>Example setup to try this out locally</b></summary>
Copy link

Choose a reason for hiding this comment

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

Inline HTML


#### Example Usage
<details>
<summary><b>Example setup to try this out locally</b></summary>
Copy link

Choose a reason for hiding this comment

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

Inline HTML

</code>
<li>
Store the token from your request in your local credential manager so
that it may be retrieved in your <code>secretless.yml</code>
Copy link

Choose a reason for hiding this comment

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

Inline HTML

examples/generic_connector_configs/README.md Show resolved Hide resolved
examples/generic_connector_configs/README.md Show resolved Hide resolved
@codeclimate
Copy link

codeclimate bot commented Jul 7, 2020

Code Climate has analyzed commit 2fba078 and detected 27 issues on this pull request.

Here's the issue category breakdown:

Category Count
Style 27

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 49.8% (0.0% change).

View more on Code Climate.

@BradleyBoutcher BradleyBoutcher merged commit c237eac into master Jul 7, 2020
@BradleyBoutcher BradleyBoutcher deleted the add-twitter-generic-example branch March 1, 2021 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

There is an example generic HTTP connector config for Twitter
3 participants