yesod-auth-1.2.0: Authentication for Yesod.

Safe HaskellNone

Yesod.Auth

Contents

Synopsis

Subsite

data family Route a1

The type-safe URLs associated with a site argument.

data AuthPlugin master

Constructors

AuthPlugin 

Fields

apName :: Text
 
apDispatch :: Method -> [Piece] -> AuthHandler master ()
 
apLogin :: (Route Auth -> Route master) -> WidgetT master IO ()
 

getAuth :: a -> Auth

class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage) => YesodAuth master where

Associated Types

type AuthId master

Methods

loginDest :: master -> Route master

Default destination on successful login, if no other destination exists.

logoutDest :: master -> Route master

Default destination on successful logout, if no other destination exists.

getAuthId :: Creds master -> HandlerT master IO (Maybe (AuthId master))

Determine the ID associated with the set of credentials.

authPlugins :: master -> [AuthPlugin master]

Which authentication backends to use.

loginHandler :: AuthHandler master RepHtml

What to show on the login page.

renderAuthMessage

Arguments

:: master 
-> [Text]

languages

-> AuthMessage 
-> Text 

Used for i18n of messages provided by this package.

redirectToReferer :: master -> Bool

After login and logout, redirect to the referring page, instead of loginDest and logoutDest. Default is False.

authHttpManager :: master -> Manager

Return an HTTP connection manager that is stored in the foundation type. This allows backends to reuse persistent connections. If none of the backends you're using use HTTP connections, you can safely return error "authHttpManager" here.

onLogin :: HandlerT master IO ()

Called on a successful login. By default, calls setMessageI NowLoggedIn.

onLogout :: HandlerT master IO ()

Called on logout. By default, does nothing

maybeAuthId :: HandlerT master IO (Maybe (AuthId master))

Retrieves user credentials, if user is authenticated.

By default, this calls defaultMaybeAuthId to get the user ID from the session. This can be overridden to allow authentication via other means, such as checking for a special token in a request header. This is especially useful for creating an API to be accessed via some means other than a browser.

Since 1.2.0

type YesodAuthPersist master = (YesodAuth master, PersistMonadBackend (YesodPersistBackend master (HandlerT master IO)) ~ PersistEntityBackend (AuthEntity master), Key (AuthEntity master) ~ AuthId master, PersistStore (YesodPersistBackend master (HandlerT master IO)), PersistEntity (AuthEntity master), YesodPersist master, Typeable (AuthEntity master))

Constraint which states that the given site is an instance of YesodAuth and that its AuthId is in fact a persistent Key for the given value. This is the common case in Yesod, and means that you can easily look up the full informatin on a given user.

Since 1.2.0

type AuthEntity master = KeyEntity (AuthId master)

If the AuthId for a given site is a persistent ID, this will give the value for that entity. E.g.:

 type AuthId MySite = UserId
 AuthEntity MySite ~ User

Since 1.2.0

Plugin interface

data Creds master

User credentials

Constructors

Creds 

Fields

credsPlugin :: Text

How the user was authenticated

credsIdent :: Text

Identifier. Exact meaning depends on plugin.

credsExtra :: [(Text, Text)]
 

setCreds

Arguments

:: YesodAuth master 
=> Bool

if HTTP redirects should be done

-> Creds master

new credentials

-> HandlerT master IO () 

Sets user credentials for the session after checking them with authentication backends.

clearCreds

Arguments

:: YesodAuth master 
=> Bool

if HTTP redirect to logoutDest should be done

-> HandlerT master IO () 

Clears current user credentials for the session.

Since 1.1.7

User functions

defaultMaybeAuthId :: (YesodAuth master, PersistMonadBackend (b (HandlerT master IO)) ~ PersistEntityBackend val, b ~ YesodPersistBackend master, Key val ~ AuthId master, PersistStore (b (HandlerT master IO)), PersistEntity val, YesodPersist master, Typeable val) => HandlerT master IO (Maybe (AuthId master))

Retrieves user credentials from the session, if user is authenticated.

This function does not confirm that the credentials are valid, see maybeAuthIdRaw for more information.

Since 1.1.2

maybeAuth :: (YesodAuth master, PersistMonadBackend (b (HandlerT master IO)) ~ PersistEntityBackend val, b ~ YesodPersistBackend master, Key val ~ AuthId master, PersistStore (b (HandlerT master IO)), PersistEntity val, YesodPersist master, Typeable val) => HandlerT master IO (Maybe (Entity val))

requireAuthId :: YesodAuthPersist master => HandlerT master IO (AuthId master)

Similar to maybeAuthId, but redirects to a login page if user is not authenticated.

Since 1.1.0

requireAuth :: YesodAuthPersist master => HandlerT master IO (Entity (AuthEntity master))

Exception

Helper

type AuthHandler master a = YesodAuth master => HandlerT Auth (HandlerT master IO) a