Search code examples
haskellreflexobelisk

Cannot find "route" and "Https" in Obelisk OAuth project


I am working on implementing Obelisk OAuth and running into 2 problems.

  1. When trying to implement this: https://github.com/obsidiansystems/obelisk-oauth/blob/master/example/backend/src/Backend.hs

I am getting:

backend/src/Backend.hs:15:1: error:
    Could not find module ‘Network.HTTP.Client.TLS’
    Perhaps you meant
      Network.HTTP.Client (from http-client-0.6.4)
      Network.HTTP.Client.Body
      Network.HTTP.Client.Core
    Use -v to see a list of the files searched for.
   |
15 | import qualified Network.HTTP.Client.TLS as Https
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, two modules loaded.

I have this in my backend.cabal build depends:

               , http-client
               , http-client-tls

When I try the other modules the error message suggests, it does not contain the functions this page needs.

  1. When I try to implement this: https://github.com/obsidiansystems/obelisk-oauth/blob/master/example/frontend/src/Frontend.hs

Using this code:

        FrontendRoute_Main -> do
            elClass "div" "content" $ do

            let r = AuthorizationRequest
                    { _authorizationRequest_responseType = AuthorizationResponseType_Code
                    , _authorizationRequest_clientId = "fake-id"
                    , _authorizationRequest_redirectUri = Just BackendRoute_OAuth
                    , _authorizationRequest_scope = []
                    , _authorizationRequest_state = Just "none"
                    }
                grantHref = authorizationRequestHref "https://app.asana.com/-/oauth_authorize" route checkedEncoder r
            elAttr "a" ("href" =: grantHref) $ text "Authorize with Asana"

I get this error:

frontend/src/Frontend.hs:360:96-100: error:
    Variable not in scope: route :: T.Text
    |
360 |                 grantHref = authorizationRequestHref "https://app.asana.com/-/oauth_authorize" route 
checkedEncoder r
    |                                                                                                ^^^^^

(I.e. the route function.)

I cannot figure out how to import this. I looked in ob hoogle and it said Snap.Core but I can't import that successfully.

Where do I get route?

These are my imports:

import Control.Monad
import qualified Data.Text as T
-- import qualified Data.Text.Encoding as TE
import Language.Javascript.JSaddle (eval, liftJSM)
import Data.Map ((!))
import Obelisk.Frontend
import Obelisk.Configs (getConfigs)
import Obelisk.Route (R)
import Obelisk.Route.Frontend
import Obelisk.Generated.Static
import Obelisk.OAuth.Authorization (AuthorizationRequest (..), AuthorizationResponseType (..), authorizationRequestHref)
import Reflex.Dom.Core
import Common.Route
import Common.DataModel
import qualified Data.Map as Map
import Data.Maybe (fromJust)
import Data.Monoid((<>))

Solution

  • Do a Google search for Network.HTTP.Client.TLS, and it will land you at:

    enter image description here

    As you can see from the URL, this is the http-client-tls package, so add that to your backend.cabal and re-start ob run.

    The reason why you didn't see this in ob hoogle is that the Hoogle server shows only the packages already in the .cabal files of the project. If also you restart ob hoogle, after adding this new package, it will now show up in Hoogle.


    As for the other error, you should always read the included example (the answer to your question is here; the README only shows snippets, not complete code.