authorization-endpoint

From IndieWebCamp
Jump to: navigation, search


An authorization endpoint is an HTTP endpoint that micropub and IndieAuth clients can use to identify a user or obtain an authorization code (which is then later exchanged for an access token) to be able to post to their website.

Contents

Creating an Authorization Endpoint

An authorization endpoint must be able to both generate authorization codes as well as verify authorization codes.

Web Sign-In Form

The site contains a web sign-in form prompting the user to enter their personal web address to sign in. Upon submitting the form, the site begins the auth process by discovering the user's auth endpoint, e.g.:

indieauth-web-sign-in.png

See http://microformats.org/wiki/web-sign-in for more UI details / possibilities.

Identification header

Every endpoint MUST return a

IndieAuth: authorization_endpoint

HTTP header in all responses.

This is used by clients to verify that the server understands the IndieAuth protocol.

Discovery

The web application checks the user's website for a link with a rel-value of "authorization_endpoint":

<link rel="authorization_endpoint" href="http://indieauth.example.org/">

Use this URL as endpoint for processing.

Authorization Endpoint

To start the sign-in flow, the user's browser will be redirected to their authorization endpoint, with additional parameters in the query string.

Directing the user's browser to the auth endpoint is usually done via a HTTP Location header, but can optionally be an <a> tag with an href set to the authorization URL.

Request

Note: Values are shown with extra linebreaks and without URL encoding for readability.

https://auth.example.org/auth
    ?me=https://aaronparecki.com/
    &client_id=https://webapp.example.org/
    &redirect_uri=https://webapp.example.org/auth/callback
    &state=1234567890
    &response_type=id

Parameters:

me
Full URI of the user's homepage
client_id
Full URI of the application's/website's home page. Used to identify the application. An authorization endpoint may show the application's icon and title to the user during the auth process.
redirect_uri
Full URI to redirect back to when the login process is finished
state
Web application-internal state variable; can contain anything
Optional. Auth endpoints MUST support them, though.
response_type
id (identification only) or code (identification + authorization)
Optional. Defaults to id.
scope
Not used and omitted in identification mode (response_type=id)
For authorization, the scope contains a value (often a verb) that the web application requests permission for, e.g. "post". Multiple values are supported, e.g. post,delete

Redirect URI verification

why is redirect_uri separate from state?
the callback URL shouldn't be dynamic per request so that callback URLs can be registered. "state" is allowed to vary per request
why should callback urls be registered?
without registration it's easier to perform a redirect attack. more background here: http://tools.ietf.org/html/rfc6749#section-3.1.2.2
how does the client website register the callback at the server?
haven't written this part up yet, but the idea is for the client to publish its registered redirect URIs on its web page with a <link> tag
since client IDs are always URLs, it's all discoverable that way
for client_id https://example.com/ a server can find its valid redirect URIs by looking for
<link rel="redirect_uri" href="https://example.com/callback">
at example.com

Verify the user

The authorization server should present an interface describing the request being made. It must indicate:

The client_id making the request
Optionally the server can include the name and logo if an h-card is found on the client_id URL.
The scope if authorization is requested.

p3k-auth-prompt.png

TODO: Example. See h-x-app.

Redirect to web application

The authorization server presents the request information to the user, and if they approve, generates an authorization code and redirects the user to the redirect URI specified.

HTTP/1.1 302 Found
Location: https://webapp.example.org/auth/callback
    ?code=xxxxxxxx
    &state=1234567890
    &me=https://aaronparecki.com/

Parameters:

code
Authorization code
state
State variable sent by the web application
me
Full URI of the user's homepage

Auth code verification

The web application finally queries the authorization endpoint to verify the auth code present in the query string. It makes a POST request to the authorization server with the following values:

POST https://auth.example.org/auth
Content-type: application/x-www-form-urlencoded

code=xxxxxxxx
&redirect_uri=https://webapp.example.org/auth/callback
&client_id=https://webapp.example.org/
&state=1234567890

After the authorization server verifies that redirect_uri, client_id and state match the code given, the response will include the "me" value indicating the URL of the user who signed in.

HTTP/1.1 200 OK
Content-Type: application/x-www-form-urlencoded

me=https://aaronparecki.com/

Parameters:

me
Full URI of the user's homepage


Using an Authorization Service

You can use an existing authorization service such as indieauth.com if you don't want to build your own authorization service.


FAQ

Why are auth codes verified with a POST instead of a GET

If auth codes are sent as a GET request in the query string, they may leak to log files or the HTTP "referer". The decision was made by the OAuth 2.0 working group to use POST requests and the HTTP Authorization header for sending these sensitive tokens and auth codes.

Can the authorization codes be used more than once

No, the authorization code must not be used more than once. If the code is used more than once, the authorization server must deny the request.[1] A maximum lifetime of 10 minutes is recommended for the authorization codes, although many implementations have a lifetime of 30-60 seconds.

Can I add additional parameters for the authorization request

No, but you can use the "state" parameter to encode or reference additional application-specific parameters. The state parameter will be passed around and was designed for this purpose as well as to prevent CSRF attacks.

Does the auth server have to support the state parameter

Yes, the state parameter can be used by the client to maintain state between the request and the callback, so the auth server must support it. It is also used to prevent CSRF attacks.


Software implementing the authorization endpoint spec

See Also

Personal tools
Namespaces
Variants
Actions
Recent & Upcoming
Resources
Toolbox