Skip to content

Yesod.Auth.Token: Yesod Auth plugin using a random token made of Text

License

Notifications You must be signed in to change notification settings

axel-angel/yesod-auth-token

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation

As this package is not published in Hackage, you should install it locally as a git submodule for your project.

  1. In the directory of your project where you put external dependancies (usually deps or lib):
# Add the repo as a submodule to your project
git submodule add https://github.com/axel-angel/yesod-auth-token.git 
  1. In your cabal file, under build-depends add yesod-auth-token
  2. Let stack know about the location of this package by adding it in stack.yml under:
# ...
packages:
- '.'
- 'lib/yesod-auth-token' # Change the dir name if needed
  1. Execute stack build to finish the installation

Example

To put in your Foundation.hs

import Yesod.Auth.Token

instance YesodAuthToken App where
    type AuthTokenId App = UserId

    setUserToken uid t = do
        runDB $ updateWhere [UserId ==. uid] [UserToken =. t]

    getTokenCreds t = do
        mUser <- runDB . getBy $ UniqueToken t
        return $ (\uid -> TokenCreds (entityKey uid) t) <$> mUser

-- stuff in between

instance YesodAuth App where
    -- stuff
    getAuthId (Creds "token" t _) = do
        mTokenCreds <- getTokenCreds t
        return $ tokenCredsAuthId <$> mTokenCreds

    -- You can add other plugins like BrowserID, email or OAuth here
    authPlugins _ = [authToken]

In your model, you can have this

User
    token Text
    nickname Text Maybe
      UniqueToken token
      deriving Typeable

About

Yesod.Auth.Token: Yesod Auth plugin using a random token made of Text

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published