Safe Haskell | None |
---|
- data Auth
- type AuthRoute = Route Auth
- data family Route a1
- data AuthPlugin master = AuthPlugin {
- apName :: Text
- apDispatch :: Method -> [Piece] -> AuthHandler master TypedContent
- apLogin :: (Route Auth -> Route master) -> WidgetT master IO ()
- getAuth :: a -> Auth
- class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage) => YesodAuth master where
- type AuthId master
- authLayout :: WidgetT master IO () -> HandlerT master IO Html
- loginDest :: master -> Route master
- logoutDest :: master -> Route master
- getAuthId :: Creds master -> HandlerT master IO (Maybe (AuthId master))
- authPlugins :: master -> [AuthPlugin master]
- loginHandler :: AuthHandler master Html
- renderAuthMessage :: master -> [Text] -> AuthMessage -> Text
- redirectToReferer :: master -> Bool
- authHttpManager :: master -> Manager
- onLogin :: HandlerT master IO ()
- onLogout :: HandlerT master IO ()
- maybeAuthId :: HandlerT master IO (Maybe (AuthId master))
- onErrorHtml :: MonadResourceBase m => Route master -> Text -> HandlerT master m Html
- type YesodAuthPersist master = (YesodAuth master, YesodPersistBackend master ~ PersistEntityBackend (AuthEntity master), Key (AuthEntity master) ~ AuthId master, PersistStore (YesodPersistBackend master), PersistEntity (AuthEntity master), YesodPersist master, Typeable (AuthEntity master))
- type AuthEntity master = KeyEntity (AuthId master)
- data Creds master = Creds {
- credsPlugin :: Text
- credsIdent :: Text
- credsExtra :: [(Text, Text)]
- setCreds :: YesodAuth master => Bool -> Creds master -> HandlerT master IO ()
- setCredsRedirect :: YesodAuth master => Creds master -> HandlerT master IO TypedContent
- clearCreds :: YesodAuth master => Bool -> HandlerT master IO ()
- loginErrorMessage :: (YesodAuth master, MonadResourceBase m) => Route master -> Text -> HandlerT master m TypedContent
- loginErrorMessageI :: (MonadResourceBase m, YesodAuth master) => Route child -> AuthMessage -> HandlerT child (HandlerT master m) TypedContent
- defaultMaybeAuthId :: (YesodAuth master, b ~ YesodPersistBackend master, b ~ PersistEntityBackend val, Key val ~ AuthId master, PersistStore b, PersistEntity val, YesodPersist master, Typeable val) => HandlerT master IO (Maybe (AuthId master))
- maybeAuth :: (YesodAuth master, b ~ YesodPersistBackend master, b ~ PersistEntityBackend val, Key val ~ AuthId master, PersistStore b, PersistEntity val, YesodPersist master, Typeable val) => HandlerT master IO (Maybe (Entity val))
- requireAuthId :: YesodAuth master => HandlerT master IO (AuthId master)
- requireAuth :: YesodAuthPersist master => HandlerT master IO (Entity (AuthEntity master))
- data AuthException = InvalidFacebookResponse
- type AuthHandler master a = YesodAuth master => HandlerT Auth (HandlerT master IO) a
- credsKey :: Text
- provideJsonMessage :: Monad m => Text -> Writer (Endo [ProvidedRep m]) ()
- messageJson401 :: MonadResourceBase m => Text -> HandlerT master m Html -> HandlerT master m TypedContent
- asHtml :: Html -> Html
Subsite
RouteAttrs Auth | |
ParseRoute Auth | |
RenderRoute Auth | |
YesodAuth master => YesodSubDispatch Auth (HandlerT master IO) | |
Eq (Route Auth) | |
Read (Route Auth) | |
Show (Route Auth) |
data family Route a1
The type-safe URLs associated with a site argument.
data AuthPlugin master Source
AuthPlugin | |
|
class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage) => YesodAuth master whereSource
authLayout :: WidgetT master IO () -> HandlerT master IO HtmlSource
specify the layout. Uses defaultLayout by default
loginDest :: master -> Route masterSource
Default destination on successful login, if no other destination exists.
logoutDest :: master -> Route masterSource
Default destination on successful logout, if no other destination exists.
getAuthId :: Creds master -> HandlerT master IO (Maybe (AuthId master))Source
Determine the ID associated with the set of credentials.
authPlugins :: master -> [AuthPlugin master]Source
Which authentication backends to use.
loginHandler :: AuthHandler master HtmlSource
What to show on the login page.
:: master | |
-> [Text] | languages |
-> AuthMessage | |
-> Text |
Used for i18n of messages provided by this package.
redirectToReferer :: master -> BoolSource
After login and logout, redirect to the referring page, instead of
loginDest
and logoutDest
. Default is False
.
authHttpManager :: master -> ManagerSource
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 ()Source
Called on a successful login. By default, calls
setMessageI NowLoggedIn
.
onLogout :: HandlerT master IO ()Source
Called on logout. By default, does nothing
maybeAuthId :: HandlerT master IO (Maybe (AuthId master))Source
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
onErrorHtml :: MonadResourceBase m => Route master -> Text -> HandlerT master m HtmlSource
Called on login error for HTTP requests. By default, calls
setMessage
and redirects to dest
.
type YesodAuthPersist master = (YesodAuth master, YesodPersistBackend master ~ PersistEntityBackend (AuthEntity master), Key (AuthEntity master) ~ AuthId master, PersistStore (YesodPersistBackend master), PersistEntity (AuthEntity master), YesodPersist master, Typeable (AuthEntity master))Source
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)Source
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
User credentials
Creds | |
|
:: 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.
:: YesodAuth master | |
=> Creds master | new credentials |
-> HandlerT master IO TypedContent |
:: YesodAuth master | |
=> Bool | if HTTP redirect to |
-> HandlerT master IO () |
Clears current user credentials for the session.
Since 1.1.7
loginErrorMessage :: (YesodAuth master, MonadResourceBase m) => Route master -> Text -> HandlerT master m TypedContentSource
For HTML, set the message and redirect to the route. For JSON, send the message and a 401 status
loginErrorMessageI :: (MonadResourceBase m, YesodAuth master) => Route child -> AuthMessage -> HandlerT child (HandlerT master m) TypedContentSource
User functions
defaultMaybeAuthId :: (YesodAuth master, b ~ YesodPersistBackend master, b ~ PersistEntityBackend val, Key val ~ AuthId master, PersistStore b, PersistEntity val, YesodPersist master, Typeable val) => HandlerT master IO (Maybe (AuthId master))Source
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, b ~ YesodPersistBackend master, b ~ PersistEntityBackend val, Key val ~ AuthId master, PersistStore b, PersistEntity val, YesodPersist master, Typeable val) => HandlerT master IO (Maybe (Entity val))Source
Similar to maybeAuthId
, but additionally look up the value associated
with the user's database identifier to get the value in the database. This
assumes that you are using a Persistent database.
Since 1.1.0
requireAuthId :: YesodAuth master => HandlerT master IO (AuthId master)Source
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))Source
Similar to maybeAuth
, but redirects to a login page if user is not
authenticated.
Since 1.1.0
Exception
data AuthException Source
Show AuthException | |
Typeable AuthException | |
Exception AuthException |
Helper
Internal
provideJsonMessage :: Monad m => Text -> Writer (Endo [ProvidedRep m]) ()Source
messageJson401 :: MonadResourceBase m => Text -> HandlerT master m Html -> HandlerT master m TypedContentSource