-
Notifications
You must be signed in to change notification settings - Fork 298
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
Support Bearer Token #132
Support Bearer Token #132
Conversation
so users can make an OAuth2 request without creating a user profile if they want... (e.g., a user who only use bearer token)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested several scenarios here (standard, premium and Labs APIs) and this works. It also doesn't seem to have corrupted my .twurlrc file which is positive :-) So, this is a tentative approval, but I do have a few things we should discuss before merging.
A few thoughts:
- I'm concerned about the complexity and clarity of the .twurlrc file, given it is now possible to have multiple accounts and apps, and also (separately, but still requiring an account to exist), bearer tokens. I wonder if there is any way to make it more clear, which tokens potentially work with which default account.
- we're using "OAuth 2", "bearer token" and "application-only" to describe this functionality in different places (twurlrc, help text, etc), and I think there's a danger of this making it more confusing. We've got some auth doc updates being worked on as well (Hamza might be able to show you these) and maybe we could find a way of only using one term (I think "app-only" or "bearer token" would be most clear).
- needs a big update to the README
- I'm not sure of the value of hiding the bearer token in the output from the oauth2_tokens command, because they are stored in plain text in the twurlrc file
@andypiper Thanks!
Agree. But, with the current interface and implementation by having a backward-compatibility, it is certainly difficult to provide such a way, is my view. For now, all we can do is to provide solid documentation and eliminate confusion as much as possible, I think.
100%, this was one of the critical ask I wanted to collect feedback from folks. When I start this implementation, since the "application-only" is our own term and not widely common, I thought "--oauth2" is more user-friendly and intuitive. But now, I'm also feeling
Will do.
Right. I just followed the same way as the |
Well, I actually prefer
$ twurl authorize --bearer -c AAA -s secret
Authorization successful $ twurl bearer_tokens
[consumer_key: bearer_token]
AAA: (omitted) |
🚀 |
I think once we've got some documentation about this in place, we can probably get this merged. |
f545d6b
to
4814044
Compare
4814044
to
7cfa1fc
Compare
@andypiper Updated README, I'll wait for your review, thanks! |
7cfa1fc
to
a8edbce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One typo in the README - after that I approve merging and shipping.
@andypiper Done! Thanks for your review |
Problem
Twurl doesn't support application-only token (OAuth2).
There were some efforts before such as #48 (#47) but it wasn't merged, unfortunately.
Solution
Using @mdeschamps 's base implementation with a bit of a customized approach.
So the key point is, how to store a bearer token in
~/.twurlrc
file. In #48, I see the original implementation was to store token by associating it to a hard-coded usernameapp-only
:but this is not an ideal approach as described in #48 (comment).
So my approach is, store bearer tokens under a new top-level object
bearer_tokens
like this:Since a bearer token doesn't have an association with
user
butApp (consumer_key + consumer_secret)
, it should not link to a user object. In the above case, each bearer token only has a link to its App (consumer_key). That is, bothuser1
anduser2
can make an OAuth2 request using a stored bearer token if the current profile's consumer_key has a link to one of those stored tokens.Example:
SUCCESS
profile:user1
, consumer_key:AAA
This should success as the consumer_key
AAA
has a stored bearer token (${bearer_token_1}
)SUCCESS
profile:user1
, consumer_key:BBB
This should success as the consumer_key
BBB
has a stored bearer token (${bearer_token_2}
)SUCCESS
profile:user2
, consumer_key:AAA
This should success as the consumer_key
AAA
has a stored bearer token (${bearer_token_1}
)ERROR
profile:user2
, consumer_key:CCC
This should fail as the consumer_key
CCC
has no stored bearer token.Auth flow
List OAuth2 tokens
(omitted)
part is actual output, theoauth2_tokens
doesn't print bearer_tokens for security reasons.Limitations
The
--oauth2
option requires at least one user profile created (in~/.twurlrc
). So if a first-time install user who only issued an OAuth2 token performs an OAuth2 request then it fails:$ cat ~/.twurlrc --- profiles: {} configuration: {} bearer_tokens: AAA: token
In this case, the user can still make an OAuth2 request by specifying the
-c
(--consumer_key) option without creating a user profile as described in the above error message.