wai-middleware-auth- Authentication middleware that secures WAI application

Safe HaskellNone





class AuthProvider ap where Source #

Core Authentication class, that allows for extensibility of the Auth middleware created by mkAuthMiddleware. Most important function is handleLogin, which implements the actual behavior of a provider. It's function arguments in order:

  • ap - Current provider.
  • Request - Request made to the login page
  • [Text] - Url suffix, i.e. last part of the Url split by '/' character, for instance ["login", "complete"] suffix in the example below.
  • Render ProviderUrl - Url renderer. It takes desired suffix as first argument and produces an absolute Url renderer. It can further be used to generate provider urls, for instance in Hamlet templates as will result in "https://approot.com/_auth_middleware/providerName/login/complete?user=Hamlet" or generate Urls for callbacks.

    @?{(ProviderUrl ["login", "complete"], [("user", Hamlet)])}
  • (UserIdentity -> IO Response) - Action to call on a successfull login.
  • (Status -> ByteString -> IO Response) - Should be called in case of a failure with login process by supplying a status and a short error message.

Minimal complete definition

getProviderName, getProviderInfo, handleLogin


getProviderName :: ap -> Text Source #

Return a name for the provider. It will be used as a unique identifier for this provider. Argument should not be evaluated, as there are many places were undefined value is passed to this function.

Since: 0.1.0

getProviderInfo :: ap -> ProviderInfo Source #

Get info about the provider. It will be used in rendering the web page with a list of providers.

Since: 0.1.0

handleLogin :: ap -> Request -> [Text] -> Render ProviderUrl -> (UserIdentity -> IO Response) -> (Status -> ByteString -> IO Response) -> IO Response Source #

Handle a login request in a custom manner. Can be used to render a login page with a form or redirect to some other authentication service like OpenID or OAuth2.

Since: 0.1.0


data Provider where Source #

Generic authentication provider wrapper.


Provider :: AuthProvider p => p -> Provider 

data ProviderUrl Source #

Data type for rendering Provider specific urls.


ProviderUrl [Text] 

type Providers = HashMap Text Provider Source #

Collection of supported providers.

Provider Parsing

type ProviderParser = (Text, Value -> Parser Provider) Source #

Aeson parser for a provider with unique provider name (same as returned by getProviderName)

mkProviderParser :: forall ap. (FromJSON ap, AuthProvider ap) => Proxy ap -> ProviderParser Source #

First argument is not evaluated and is only needed for restricting the type.

parseProviders :: Object -> [ProviderParser] -> Result Providers Source #

Parse configuration for providers from an Object.


data AuthUser Source #

Representation of a user for a particular Provider.


Show AuthUser Source # 
Generic AuthUser Source # 

Associated Types

type Rep AuthUser :: * -> * #


from :: AuthUser -> Rep AuthUser x #

to :: Rep AuthUser x -> AuthUser #

Binary AuthUser Source # 


put :: AuthUser -> Put #

get :: Get AuthUser #

putList :: [AuthUser] -> Put #

type Rep AuthUser Source # 
type Rep AuthUser = D1 (MetaData "AuthUser" "Network.Wai.Middleware.Auth.Provider" "wai-middleware-auth-" False) (C1 (MetaCons "AuthUser" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "authUserIdentity") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 UserIdentity)) ((:*:) (S1 (MetaSel (Just Symbol "authProviderName") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ByteString)) (S1 (MetaSel (Just Symbol "authLoginTime") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int64)))))

type UserIdentity = ByteString Source #

An arbitrary user identifer, eg. a username or an email address.


mkRouteRender :: Maybe Text -> Text -> [Text] -> Render Provider Source #

Create a url renderer for a provider.

providersTemplate Source #


:: Maybe Text

Error message to display, if any.

-> Render Provider

Renderer function for provider urls.

-> Providers

List of available providers.

-> Builder 

Template for the providers page