hsoz-0.0.1.0: Iron, Hawk, Oz: Web auth protocols

Safe HaskellNone
LanguageHaskell2010

Network.Hawk.Client

Contents

Description

Functions for making Hawk-authenticated request headers and verifying responses from the server.

The easiest way to make authenticated requests is to use withHawk with functions from the Network.HTTP.Simple module (from the http-conduit package).

Synopsis

Higher-level API

withHawk Source #

Arguments

:: (MonadIO m, MonadCatch m) 
=> Credentials

Credentials for signing the request.

-> Maybe ExtData

Optional application-specific data.

-> Maybe PayloadInfo

Optional payload to sign.

-> ServerAuthorizationCheck

Whether to verify the server's response.

-> (Request -> m (Response body))

The action to run with the request.

-> Request

The request to sign.

-> m (Response body)

The result of the action.

Signs and executes a request, then checks the server's response. Handles retrying of requests if the server and client clocks are out of sync.

A HawkException will be thrown if the server's response fails to authenticate.

Types

data ServerAuthorizationCheck Source #

Whether the client wants to check the received Server-Authorization header depends on the application.

data HawkException Source #

Client exceptions specific to Hawk.

Constructors

HawkServerAuthorizationException String

The returned Server-Authorization header did not validate.

data Credentials Source #

ID and key used for encrypting Hawk Authorization header.

Constructors

Credentials 

Instances

Protocol functions

sign Source #

Arguments

:: MonadIO m 
=> Credentials

Credentials for signing

-> Maybe ExtData

Optional application-specific data.

-> Maybe PayloadInfo

Optional payload to hash

-> NominalDiffTime

Time offset to sync with server time

-> Request

The request to sign

-> m (HeaderArtifacts, Request) 

Modifies a Request to include the Authorization header necessary for Hawk.

authenticate Source #

Arguments

:: Response body

Response from server.

-> Credentials

Credentials used for signing the request.

-> HeaderArtifacts

The result of sign.

-> Maybe ByteString

Optional payload body from response.

-> ServerAuthorizationCheck

Whether a valid Server-Authorization header is required.

-> IO (Either String (Maybe ServerAuthorizationHeader))

Error message if authentication failed.

Validates the server response from a signed request. If the payload body is provided, its hash will be checked.

header Source #

Arguments

:: Text

The request URL

-> Method

The request method

-> Credentials

Credentials used to generate the header

-> Maybe PayloadInfo

Optional request payload

-> NominalDiffTime

Time offset to sync with server time

-> Maybe ExtData

Application-specific ext data

-> IO Header 

Generates the Hawk authentication header for a request.

headerOz Source #

Arguments

:: Text

The request URL

-> Method

The request method

-> Credentials

Credentials used to generate the header

-> Maybe PayloadInfo

Optional request payload

-> NominalDiffTime

Time offset to sync with server time

-> Maybe ExtData

Application-specific ext data

-> Text

Oz application identifier

-> Maybe Text

Oz delegated application

-> IO Header 

Generates the Hawk authentication header for an Oz request. Oz requires another attribute -- the application id. It also has an optional delegated-by attribute, which is the application id of the application the credentials were directly issued to.

getBewit Source #

Arguments

:: Credentials

Credentials used to generate the bewit.

-> NominalDiffTime

Time-to-live (TTL) value.

-> Maybe ExtData

Optional application-specific data.

-> NominalDiffTime

Time offset to sync with server time.

-> ByteString

URI.

-> IO (Maybe ByteString)

Base-64 encoded bewit value. fixme: javascript version supports deconstructed parsed uri objects fixme: not much point having two time interval arguments? Maybe just have a single expiry time argument.

Generate a bewit value for a given URI. If the URI can't be parsed, Nothing will be returned.

See Network.Hawk.URI for more information about bewits.

message Source #

Arguments

:: Credentials

Credentials for encryption.

-> ByteString

Destination host.

-> Maybe Int

Destination port.

-> ByteString

The message.

-> NominalDiffTime

Time offset to sync with server time.

-> IO MessageAuth 

Generates an authorization object for a Hawk signed message.

Types

data Header Source #

The result of Hawk header generation.

Constructors

Header 

Fields

Instances

Show Header Source # 
Generic Header Source # 

Associated Types

type Rep Header :: * -> * #

Methods

from :: Header -> Rep Header x #

to :: Rep Header x -> Header #

type Rep Header Source # 
type Rep Header = D1 (MetaData "Header" "Network.Hawk.Internal.Client.Types" "hsoz-0.0.1.0-5r17DkUA43zE9P6QhuhthQ" False) (C1 (MetaCons "Header" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "hdrField") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Authorization)) (S1 (MetaSel (Just Symbol "hdrArtifacts") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeaderArtifacts))))

type Authorization = ByteString Source #

The value of an Authorization header.