Search code examples
haskellyesod

Yesod 1.2 Authorization


I'm working on a Yesod-based website. I had been reading the Yesod book online, and I ran into an inconvenient discrepancy (Yes, I know the book is out of date). Usually I can just Google around these discrepancies, but I don't know where to start.

In particular, I'm trying to set up authorization for some routes. The Yesod book says I should define

instance YesodAuth MyApp where
  isAuthorized RouteR _ = <check for stuff and return an authorization token>

But that method is not defined in Yesod.Auth.YesodAuth anymore. What is the current state of the craft?


Solution

  • I see you already found the answer, but in the future, you may be able to find it more quickly by using a more specialized tool than Google. Probably the best Haskell API search engine for Yesod is this one: FPComplete's Hoogle Search.

    There's also the Haskell.org Hoogle Search

    And Holumbus's Hayoo Search, at least when it is up. It's down as I'm typing this, but it should return at some point.

    Both the Hoogle and Hayoo allow you to search both on function/package names as well as on function signatures, so if you know what the function you want does but not what it's called you can still search for it! They do vary a bit on how they interpret the type you give them and what packages they search by default, so you may want to keep both links handy and try queries on both.

    Note that the FPComplete Hoogle searches in all of the packages it indexes by default, while the main Haskell.org one will only search in Haskell Platform packages by default, but will also search in other packages on Hackage if you explicitly ask it to by adding +<package name> to your query string, e.g. isAuthorized +yesod-core for your question.

    Based on this haskell-cafe thread the Haskell.org Hoogle search engine will probably have this restriction lifted at some point, but meanwhile you should probably use one of the alternatives I listed if you don't know the package name and you don't think what you're searching for is in the Haskell Platform.

    Finally, you can download the hoogle code from Hackage (via cabal install) and it will give you a local package index that you can query from the command line or integrate into an editor. This can be pretty handy for quick look-up of a function that you know exists in the Platform but you can't quite remember the details of.