authorization-endpoint

From IndieWeb


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.

Authorization Endpoint Flows

Flows Required by the Spec

From a client app’s point of view (and as required by the indieauth spec), an authorization endpoint must support the following request flows:

  • A GET request (sent from the user’s browser via a redirect) with a query string containing authorization code request parameters. The response to this request is shown to the user, and is out of scope of the spec, but if successful it should result in the user being redirected to the redirect_uri parameter with code and state query string parameters.
  • A POST request to exchange an authorization code for profile information. Should return a JSON response body with either an error or a me response, optionally with profile information.

In practice, the authorization endpoint typically has to handle authenticating the user, presenting a consent screen, and handling the consent screen form submission, before redirecting to the client app’s redirect_uri. A common way to handle this is as follows:

  • authorization request: a GET request which the user was redirected to from their client app, with code request parameters in the query string.
    • If the request is not authenticated (i.e. the user is currently logged out): perform authentication (usually by redirecting to a login page) and restart the flow.
    • If the request is authenticated (i.e. the user is currently logged in): validate the code request parameters, and return either an error response if invalid, or a consent screen response if valid.
  • consent form submission: a POST request containing data submitted from the consent screen form. MUST be CSRF-protected.
    • If the submitted data is invalid, return an error response
    • If the submitted data is valid, build an authorization code, and return a 302 Redirect response to the redirect_uri, with state and code query parameters.
  • auth code exchange for profile information: a POST request with auth code which results in a JSON response. Similar to the token endpoint flow. MUST NOT be CSRF-protected.
    • If the provided code, verifier and client ID are valid, return a JSON response containing {"me": "https://me.example.com"} and optionally profile information.
    • If the request was invalid, return a JSON OAuth2 error response

The consent screen is specific to the authorization server, and can vary widely in design and capabilities from server to server. See Consent Screen for more UI examples.