-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[RFC] Authentication and Authorization API #473
Comments
Technically, an application only has to subscribe in order for a desired channel to be tracked by the instance (see #469). It would be possible for a client to subscribe and then unsubscribe so that the |
POST and DELETE should be used for Just updated the above, DELETE is not used for |
Added with 2a6c81a. There are a couple changes from what's proposed above, and clarification on anything that's missing:
<form action="https://invidio.us/api/v1/auth/tokens/register" method="post">
<input type="text" name="scopes[0]" value="GET:subscriptions*">
<input type="text" name="scopes[1]" value="POST:tokens/register">
<input type="text" name="scopes[2]" value="POST:tokens/unregister">
<input type="text" name="callbackUrl" value="https://www.example.com/callback">
<input type="submit" value="submit">
</form> Which will require the user to authorize the token as expected.
Currently the only API endpoints that require authentication are for tokens themselves. Unless there is any unexpected/unspecified behavior I'll close this and work on adding the other endpoints ( |
Added |
Added |
Please provide a web form for the registration of new tokens. I added this simple HTML to a file and opened that in the browser so I could easily create tokens for testing purposes, but it would be really nice if Invidious had its own page for this. Maybe link to this page from the token manager page?
I cannot simply use curl to test because the initial token creation request redirects to a "confirm authorisation" web form with a CSRF token, and it would be very inconvenient to simulate the completion of that second form with curl. |
It would be convenient if the token manager page also showed the list of scopes that the token is authorised to access, to allow me to easily tell tokens apart. Or, allow some sort of optional "label" to be provided during the token creation process, and display this label next to its token. |
Since this is apparently the thread to be in:
(a long pause of over a minute without curl exiting, then finally prints this and exits)
|
You might try using GET
Sounds good.
I'm having trouble reproducing this locally, testing both
I'll try testing it out a bit more to see if there's an issue with Content-Length or some other bug with an empty response, although currently I suspect the issue is with HAProxy or some middlewhere somewhere. Probably better to open this as a new issue. |
Appears to be a bug in curl, reported here: curl/curl#3968. |
Added |
While it is certainly desirable to allow the user to control access to their account, this behaviour limits the capability of applications using the API to make authentication as painless as possible to the user. Especially in an environment where including or accessing a webbrowser is not possible, this makes it necessary to either store the credentials in the application (to allow for cookie-based authentication) or to have the user create the token on another device and then copy it over to the application in some way. To circumvent this, it may be a good idea to take a page out of Google's book. To authorize the YouTube addon for Kodi to access features of a user's account, the addon requests a code from YouTube and then prompts the user to visit a webpage at google.com (formerly at youtube.com) and enter that code there. The webpage then allows the user to decide whether they want to authorize the addon to access the requested features. It would be great if Invidious would include such a page as well as this would allow for, say, the development of a matching Kodi addon. :) Note that this approach differs from that described by @cloudrac3r above in that the latter still requires the user to copy the token over to the application. |
This will be amazing and will allow third party apps to be made for Invidious accounts such as NewPipe. |
This issue has been automatically marked as stale and will be closed in 30 days because it has not had recent activity and is much likely outdated. If you think this issue is still relevant and applicable, you just have to post a comment and it will be unmarked. |
Bump |
Any news on this? |
@jxxp9 I'll see what I can do. I can't promise that this will be implemented soon, but I'm considering it! |
Related: #427, #469
For various applications it is desirable to be able to read or write user data. This proposal describes a format for tokens, a method for authenticating requests, and endpoints for authorizing tokens.
Token format
Each token is a JSON object with the following schema:
Tokens will be created with a given
session
, which allows them to be revoked by the user.Tokens may be issued with an
expire
timestamp after which the token will be considered invalid.Tokens will have a list of one or more
scopes
determining their permissions. The format forscopes
is described below.Tokens will have a
signature
to ensure integrity of the other fields.Example token:
Authentication
All sub-routes of
/api/v1/auth
must be authenticated.Endpoints requiring authentication are authenticated with an
Authentication: Bearer <token>
header.Tokens are validated by taking all key-value pairs, minus
signature
, and creating the following string:Values are alpha-sorted. Keys are alpha-sorted and joined by newlines. There is no trailing newline.
The
signature
is created by signing the string using SHA256-HMAC with the instance'sHMAC_KEY
and Base64 encoded.Using the above token as an example:
Signed using
SECRET_KEY
provides the signaturef//2hS20th8pALF305PJFK+D2aVtvefNnQheILHD2vU=
.Scoping
In order to provide a means of limiting permissions for an application, tokens must provide one or more
scopes
.Each
scope
refers to a sub-route of/api/v1/auth
. Scopes are defined as zero or more HTTP methods (semicolon-separated), colon (:), followed by an endpoint and optional wildcard for matching sub-routes.A scope X is said to be
containing
scope Y if X can match Y, but Y cannot match X. For example,:subscriptions*
containsGET:subscriptions/subscribe
.Example scope allowing access to
/api/v1/auth/subscriptions
using any method:Example scope allowing access to
/api/v1/auth/subscriptions
and any sub-routes using any method:Example scope allowing access to any sub-routes of
/api/v1/auth/subscriptions/
using only GET and POST:Example scope allowing access to any endpoint using any method:
A SID cookie is equivalent to a token with
"scopes": [":*"]
.POST
/api/v1/auth/tokens/register
The
/api/v1/auth/tokens/register
endpoint would support the following body (Content-Type: application/json
):Calls to
/api/v1/auth/tokens/register
must already be authenticated in order to receive a new token. This can be accomplished by a signed in user or with aBearer
token with a scope containingPOST:tokens/register
.Calls made using a
Bearer
token can only create tokens with equivalent or subsets of their own scopes.If calls are made using a SID cookie, the user will be presented with a page presenting the requested scopes, and must then authorize the request before being redirected to
callbackUrl
. If nocallbackUrl
is provided, then after authorizing the token the user will be redirected to a page on the instance containing the newly created token.If a
callbackUrl
is provided, then after successful authorization the instance will redirect tocallbackUrl
with?access_token=<token>
set as the query.POST
/api/v1/auth/tokens/unregister
The
/api/v1/auth/tokens/unregister
endpoint would support the following body:Tokens can be unregistered by calling
/api/v1/auth/tokens/unregister
. A token must have a scope containingPOST:tokens/unregister
in order to unregister itself. In order to unregister other tokens a token must have a scope containingGET:tokens
andPOST:tokens/unregister
.If the response body is empty, or
session
is not provided the token is assumed to be unregistering itself.Users would also be provided a
/list_tokens
endpoint for viewing and degistering tokens they had authorized.Example endpoints
All endpoints below are sub-routes of
/api/v1/auth
./preferences
- Would allow GET of current preferences, or POST with updated preferences/notifications
- Same as/api/v1/notifications
with support for?since=
, see [RFC] Push Notifications API #469/subscriptions
- Shows list of currently subscribed channels by the user/subscriptions/:ucid
- Subscribe to givenucid
/subscriptions/:ucid
- Unsubscribe to givenucid
/tokens
- Lists tokens authorized by user/tokens/register
/tokens/unregister
Example of use
For an application with a shared pool of users, such as FreeTube or CloudTube, an example token could be:
This would allow clients to use
?since=TIMESTAMP
to receive any notifications missed when offline, andsubscribe
to new channels.DELETE:subscriptions/*
is not included here to prevent unsubscribing to channels that still may need to be tracked by other clients.The text was updated successfully, but these errors were encountered: