implement OAuth 2.0 Authorization Code Grant #205
Loading…
Reference in a new issue
No description provided.
Delete branch "oauth"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This adds the possibility to use the OAuth 2.0 Authorization Code Grant type to obtain an API token.
The token can then be used - as was already implemented - as an OAuth 2.0 Bearer Token.
Maybe also interesting: https://qwertqwefsday.eu/oauth2-0-foundkey.html
I think we could expand the current API and data model insofar as making it possible to set per token permissions.
The idea would be that when registering an app, you have to give what are the most wide permissions the app is ever going to use. Then when you want to get the token you can give a subset of those permissions only.
(Just as a sanity check that is is not completely crazy: Mastodon seems to do this too)
Recommend merge with merge commit: There are separate changelog entries, but no overall entry.
Another question is: do we want to implement any of the following?Since nobody stopped me I added some of them as todo items.Proof Key for Code Exchange (PKCE, RFC 7636)This is an extension of the Authorization Code Grant implemented here that should make it even more secure. (Question: How secure does it have to be if we retain the other auth methods...)
OAuth discovery (RFC 8414)This would be a standardized version of the
api/app/*
endpoints, although I haven't checked if they would be compatiblebadb94bd6f
to3c9422dcb0
3c9422dcb0
to3e9217dcd1
3e9217dcd1
to1365419a43
3d2924f900
to1313c2e3ee
1313c2e3ee
toffaff820d9
ffaff820d9
tob7d2e9b11a
b7d2e9b11a
to4912fb286c
From my testing this seems to work now. Review and more testing by others appreciated.
WIP: implement OAuth 2.0 Authorization Code Grantto implement OAuth 2.0 Authorization Code GrantI'm SO sorry for taking so long with this. There's been .. stuff going on.
I'll buy you a nice tea or cofe at the next meetup to make up for it :)
From my side this looks good. I tested it with a little cli app on top of
golang.org/x/oauth2
and it worked fine. One thing that would be cool to have is support for aurn:ietf:wg:oauth:2.0:oob
redirect URI, though I can see that this is likely an edge case (and at any rate perfectly fine as a later addition).@ -69,0 +66,4 @@
function oauth(ctx) {
ctx.body = oauthMeta;
ctx.type = 'application/json';
ctx.set('Cache-Control', 'max-age=31536000, immutable');
Does it really make sense to cache this immutably for a year?
I know most of this endpoint's content is rather static, but it may lead to problems when an update is published that shifts URLs around or introduces new scopes for some fancy new feature with clients still using the old cached value, especially since
immutable
turns off revalidation 🤔There isn't any guidance in the RFCs on this as far as I could tell. I did cross-check what my organization's okta server does though and it seems they limit this endpoint to
Cache-Control: max-age=86400, must-revalidate
which looks like a reasonable tradeoff.Maybe some food for thought.
4912fb286c
to51f1bbf54c
6583c3a2be
to7924d5d01b
Can't see anything wrong with it, but I'm not in a position to test right now.
This seems to break compatibility with apps like SubwayTooter. Reading works, but trying to toot produces "This operation requires privileges which this token does not grant.". Trying to log out and back in results in the browser loading the auth page but it remains blank with a loading animation.
Do you have a database backup before the migration?
I'm guessing the migration
tokenPermissions1667653936442
is incorrect but I am not sure what is wrong.Sadly no. Since I tried it on a mobile device it's quite difficult debugging what goes on in the browser console but I'm sure something shows up there.
Hmm I've downloaded subway tooter and authorized it for my account on my instance which does not have this merged yet. I then copied the
app
andacces_token
tables to a testing database and performed the migration there, but everything seems fine. I'm not sure if there was maybe a previous bug in subway tooter that may have cause this. But then I think it should not have worked before.Anyway, to be sure that it is not the database, can you check the permissions that are currently given to subway tooter in your database are correct?
Database querying instructions
To do this, first run this query:
There should be one result. Then run this query, replacing
<app id>
with the id from the request before.Also for this query there should be one result. Both
permission
values should be the same.For cross-checking, this is what permissions I found in my database after authorizing subway tooter:
I authorized the app back when I was using Misskey, so perhaps that could be why this is happening. The first query does return one entry, but the second query gets me 3 results. Two from 2022-12-05, and the original from 2022-05-01. All matching the permissions from your comment, oddly.
Worth noting that I created an access token by hand to use within SubwayTooter so I can continue tooting for now, but I'm not sure if that would be listed by searching for SubwayTooter?
In the meantime I have tried upgrading my instance to include these changes while having subway tooter registered. I can still post after upgrading so I can't reproduce your problem. Maybe it really was because of an older subway tooter version.