home: github.com/shurcooL/home/indieauth Index | Files

package indieauth

import "github.com/shurcooL/home/indieauth"

Package indieauth implements building blocks for the IndieAuth specification (https://indieauth.spec.indieweb.org/).

The functionality and API of this package is v0, meaning it is in early development and may change. There are no compatibility guarantees made.

Index

Package Files

client.go fetch.go indieauth.go

func MeFlag Uses

func MeFlag(name string, value string, usage string) *meFlag

MeFlag defines a user profile URL flag with specified name, default value, and usage string. The return value is the address of a meFlag variable that stores the value of the flag. The flag accepts the canonical form of a value acceptable to ParseUserProfile, or the empty string. MeFlag panics if the provided default value is not acceptable.

func ParseClientID Uses

func ParseClientID(clientID string) (*url.URL, error)

ParseClientID parses a client ID URL that a client is identified by.

It verifies the restrictions as described in the IndieAuth specification at https://indieauth.spec.indieweb.org/#client-identifier:

Client identifier URLs
	MUST have either an https or http scheme,
	MUST contain a path component,
	MUST NOT contain single-dot or double-dot path segments,
	MAY contain a query string component,
	MUST NOT contain a fragment component,
	MUST NOT contain a username or password component, and
	MAY contain a port.
Additionally, hostnames
	MUST be domain names or a loopback interface and
	MUST NOT be IPv4 or IPv6 addresses except for IPv4 127.0.0.1 or IPv6 [::1].

It applies a few additional restrictions for now.

func ParseUserProfile Uses

func ParseUserProfile(me string) (*url.URL, error)

ParseUserProfile parses a user profile URL that a user is identified by.

It verifies the restrictions as described in the IndieAuth specification at https://indieauth.spec.indieweb.org/#user-profile-url:

Profile URLs
	MUST have either an https or http scheme,
	MUST contain a path component (/ is a valid path),
	MUST NOT contain single-dot or double-dot path segments,
	MAY contain a query string component,
	MUST NOT contain a fragment component,
	MUST NOT contain a username or password component, and
	MUST NOT contain a port.
Additionally, hostnames
	MUST be domain names and
	MUST NOT be ipv4 or ipv6 addresses.

It applies a few additional restrictions for now.

type Client Uses

type Client struct {
    // ClientID is the URL that an IndieAuth client is identified by.
    //
    // It must be an absolute URL that follows rules described at
    // https://indieauth.spec.indieweb.org/#client-identifier.
    ClientID string

    // RedirectURL is the URL to redirect users going through the
    // IndieAuth authentication flow, after approving the request.
    //
    // The URL scheme, host and port should match that of the ClientID.
    // See https://indieauth.spec.indieweb.org/#authentication-request.
    RedirectURL string
}

Client describes an IndieAuth client application that is configured to perform the IndieAuth authentication flow. (The IndieAuth authorization flow is not supported yet.)

See https://indieauth.spec.indieweb.org/#authentication.

func (*Client) AuthnReqURL Uses

func (c *Client) AuthnReqURL(authzEndpoint *url.URL, me, state string) string

AuthnReqURL returns the authentication request URL for the given user profile and state.

See https://indieauth.spec.indieweb.org/#authentication-request.

func (*Client) Verify Uses

func (c *Client) Verify(ctx context.Context, authzEndpoint, enteredHost, code string) (me *url.URL, _ error)

Verify makes a POST request to the authorization endpoint to verify the authorization code and retrieve the final user profile URL.

An error is returned if the final user profile URL has a host that does not equal enteredHost, the host of the entered user profile URL.

See https://indieauth.spec.indieweb.org/#authorization-code-verification and https://indieauth.spec.indieweb.org/#differing-user-profile-urls.

type UserProfile Uses

type UserProfile struct {
    CanonicalMe   *url.URL // Canonical user profile URL (taking redirects into account).
    AuthzEndpoint *url.URL // URL of IndieAuth authorization endpoint, or nil if there isn't one.
}

UserProfile is the parsed result of fetching a user profile URL with an HTTP GET request.

func FetchUserProfile Uses

func FetchUserProfile(ctx context.Context, t http.RoundTripper, me *url.URL) (UserProfile, *html.Node, error)

FetchUserProfile fetches the user profile specified by me, which must be a valid user profile URL, by making an HTTP GET request to the URL. It returns an error if the request fails, or if the response status code is not 200 OK.

As a matter of policy, it does not include raw bytes from the response body of the HTTP GET request in error messages.

The caller is responsible for enforcing a timeout.

Package indieauth imports 15 packages (graph) and is imported by 3 packages. Updated 2020-07-24. Refresh now. Tools for package owners.