yesod-auth-deskcom-1.2: Desk.com remote authentication support for Yesod apps.

Safe HaskellNone

Yesod.Auth.DeskCom

Synopsis

Documentation

class YesodAuthPersist master => YesodDeskCom master whereSource

Type class that you need to implement in order to support Desk.com remote authentication.

Minimal complete definition: everything except for deskComTokenTimeout.

Methods

deskComCredentials :: master -> DeskComCredentialsSource

The credentials needed to use Multipass. Use deskComCreateCreds. We recommend caching the resulting DeskComCredentials value on your foundation data type since creating it is an expensive operation.

deskComUserInfo :: AuthId master -> HandlerT master IO DeskComUserSource

Gather information that should be given to Desk.com about an user. Please see DeskComUser for more information about what these fields mean.

Simple example:

 deskComUserInfo uid = do
   user <- runDB $ get uid
   return def { duName  = userName user
              , duEmail = userEmail user }

Advanced example:

 deskComUserInfo uid = do
   render <- getUrlRender
   runDB $ do
     Just user <- get uid
     Just org  <- get (userOrganization user)
     return def { duName           = userName user
                , duEmail          = userEmail user
                , duOrganization   = Just (organizationName org)
                , duRemotePhotoURL = Just (render $ UserPhotoR uid)
                }

Note: although I don't recomend this and I don't see any reason why you would do it, it is possible to use maybeAuth instead of requireAuth and login on Desk.com with some sort of guest user should the user not be logged in.

deskComTokenTimeout :: master -> NominalDiffTimeSource

Each time we login an user on Desk.com, we create a token. This function defines how much time the token should be valid before expiring. Should be greater than 0. Defaults to 5 minutes.

deskComCreateCredsSource

Arguments

:: Text

The name of your site (e.g., "foo" if your site is at http:foo.desk.com/).

-> Text

The domain of your site (e.g. "foo.desk.com").

-> Text

The Multipass API key, a shared secret between Desk.com and your site.

-> DeskComCredentials 

Create the credentials data type used by this library. This function is relatively expensive (uses SHA1 and AES), so you'll probably want to cache its result.

data DeskComCredentials Source

Credentials used to access your Desk.com's Multipass.

data DeskComUser Source

Information about a user that is given to DeskCom. Please see Desk.com's documentation (http://dev.desk.com/docs/portal/multipass) in order to see more details of how theses fields are interpreted.

Only duName and duEmail are required. We suggest using def.

Constructors

DeskComUser 

Fields

duName :: Text

User name, at least two characters. (required)

duEmail :: Text

E-mail address. (required)

duUserId :: DeskComUserId

Desk.com expects an string to be used as the ID of the user on their system. Defaults to UseYesodAuthId.

duCustomFields :: [DeskComCustomField]

Custom fields to be set.

duRedirectTo :: Maybe Text

When Just url, forces the user to be redirected to url after being logged in. Otherwise, the user is redirected either to the page they were trying to view (if any) or to your portal page at Desk.com.

Instances

data DeskComUserId Source

Which external ID should be given to Desk.com.

Constructors

UseYesodAuthId

Use the user ID from persistent's database. This is the recommended and default value.

Explicit Text

Use this given value.

type DeskComCustomField = (Text, Text)Source

The value of a custom customer field as (key, value). Note that you have prefix your key with "custom_".

data DeskCom Source

Data type for yesod-auth-deskCom's subsite.

initDeskCom :: IO DeskComSource

Initialize the DeskCom subsite with a fresh CPRNG.

deskComLoginRoute :: Route DeskComSource

Redirect the user to Desk.com such that they're already logged in when they arrive. For example, you may use deskComLoginRoute as the login URL on Multipass config.

deskComMaybeLoginRoute :: Route DeskComSource

If the user is logged in, redirect them to Desk.com such that they're already logged in when they arrive (same as deskComLoginRoute). Otherwise, redirect them to Desk.com without asking for credentials. For example, you may use deskComMaybeLoginRoute when the user clicks on a "Support" item on a menu.