-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Unfortunately, I think we need to support bearer tokens, as it looks like this is the method used for many data access methods in new software. For example, for the SRCNet we use the token version of Rucio (from CERN) to access the data for all the clients (including command line ones)
I imagine the problem is that a bearer token cannot easily be obtained in command line so the reactive approach is difficult, doesn't it? However, I think it is better to add support and explain the problems if the consensus is that this is not a preferred method. Something like:
Bearer Token Authentication
The ivoa_bearer authentication scheme allows VO services to request authentication via Bearer tokens, aligning with OAuth 2.0 standards. This scheme is compatible with automated clients and supports token expiration and refresh workflows.
ivoa_bearer
Scheme Parameters (in WWW-Authenticate header)
When a protected resource is accessed without valid authentication, the service may respond:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: ivoa_bearer
access_url="https://example.org/auth/token",
standard_id="ivo://ivoa.net/sso#oauth2-password",
refresh_url="https://example.org/auth/refresh"
- access_url (required): URL to obtain a Bearer token using the method described in standard_id
- standard_id (required): Identifies the grant type or login protocol used
- refresh_url (optional): URL to use a refresh_token to get a new access_token
- token_type (optional): Defaults to Bearer; can be omitted
Authentication Response
A successful token acquisition response SHOULD follow OAuth2 conventions:
{
"access_token": "abc123",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "xyz789"
}
Permit Usage
Once the client has the access token, it must include it in an Authorisation header for protected resources:
Authorization: Bearer abc123
Token Expiry and Refresh
Tokens SHOULD include expires_in so clients can anticipate expiry.
If a refresh_token is returned, the client can use it at the refresh_url:
curl -X POST https://example.org/auth/refresh \
-d 'grant_type=refresh_token&refresh_token=xyz789'
If a token is used after expiration, the server SHOULD return a 401 or 403 with:
WWW-Authenticate: ivoa_bearer
error="expired_token",
access_url="https://example.org/auth/token",
standard_id="ivo://ivoa.net/sso#oauth2-password",
refresh_url="https://example.org/auth/refresh"
Optionally, the server MAY also include:
X-VO-Auth-Error: expired_token
This allows clients to distinguish an expired token from an invalid one and take appropriate action.
CLI and Non-Browser Client Support
To avoid reliance on browser-based OAuth2 flows, services that use ivoa_bearer SHOULD support at least one of the following standard_id methods:
- ivo://ivoa.net/sso#oauth2-client-credentials: for client ID + secret auth (non-user)
- ivo://ivoa.net/sso#oauth2-password: user provides username + password
- ivo://ivoa.net/sso#oauth2-device-code: device login with browser-prompted user action
Clients can discover the correct flow from the standard_id in the challenge.
Example CLI Flow (Password Grant)
Receive challenge:
WWW-Authenticate: ivoa_bearer access_url="https://example.org/auth/token",
standard_id="ivo://ivoa.net/sso#oauth2-password"
Get token:
curl -X POST https://example.org/auth/token \
-d 'grant_type=password&username=gertrude&password=xxxx'
Use token:
curl -H "Authorization: Bearer abc123" https://example.org/data/securefile.fits
Refresh when expired:
curl -X POST https://example.org/auth/refresh \
-d 'grant_type=refresh_token&refresh_token=xyz789'
If you agree with the approach, I can update the text accordingly