servant-oauth2-examples-0.1.0.1: Example applications using this library in three ways.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Servant.OAuth2.Examples.Simple

Description

This is the simplest example of a full application that makes use of this library.

We don't do anything with the result of successful authentication other than return the ident that was provided to us. In an "real" example, you'll want to set a cookie. For that, you can take a look at Servant.OAuth2.Examples.Cookies.

This file serves as a complete example; and you can read through this documentation from top to bottom, in order to work out what each component is.

Synopsis

Documentation

type OAuth2Result = '[WithStatus 200 Text] Source #

First, we need to define an instance that corresponds to the result we want to return. We're going with the basic option; so we'll just take the Text value of the ident that comes back. Note that this is a _list_ of potential return kinds; the reason it's set up this way is only so we can explicitly say we'd like to return a 303 Redirect, when using cookies.

Since: 0.1.0.0

data Routes mode Source #

Here we just define a very simple website, something like:

 /
 /auth/github/...
 /auth/google/...

The authGoogle and authGithub routes will not be implemented by us; they are both provided by a 'NamedRoutes (OAuth2Routes OAuth2Result)' value; i.e. the routes themselves come from OAuth2.

Since: 0.1.0.0

Constructors

Routes 

Fields

Instances

Instances details
Generic (Routes mode) Source # 
Instance details

Defined in Servant.OAuth2.Examples.Simple

Associated Types

type Rep (Routes mode) :: Type -> Type #

Methods

from :: Routes mode -> Rep (Routes mode) x #

to :: Rep (Routes mode) x -> Routes mode #

type Rep (Routes mode) Source # 
Instance details

Defined in Servant.OAuth2.Examples.Simple

type Rep (Routes mode) = D1 ('MetaData "Routes" "Servant.OAuth2.Examples.Simple" "servant-oauth2-examples-0.1.0.1-EmzJtQfsyJPG4cNzNv1mEY" 'False) (C1 ('MetaCons "Routes" 'PrefixI 'True) (S1 ('MetaSel ('Just "home") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (mode :- Get '[HTML] Html)) :*: (S1 ('MetaSel ('Just "authGithub") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (mode :- (AuthProtect Github :> ("auth" :> ("github" :> NamedRoutes (OAuth2Routes OAuth2Result)))))) :*: S1 ('MetaSel ('Just "authGoogle") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (mode :- (AuthProtect Google :> ("auth" :> ("google" :> NamedRoutes (OAuth2Routes OAuth2Result)))))))))

mkGithubSettings :: OAuthConfig -> OAuth2Settings Handler Github OAuth2Result Source #

We need to build an OAuth2Settings to pass to oauth2AuthHandler, so that it knows which provider it is working with. We also need to tag it with a Handler-like monad that can interpret errors; in the simple case this is just the Handler type itself, but in later examples (in particular the Servant.OAuth2.Examples.Authorisation example) it will be a custom monad.

Since: 0.1.0.0

mkGoogleSettings :: OAuthConfig -> OAuth2Settings Handler Google OAuth2Result Source #

Exactly the same as mkGithubSettings but for the Google provider.

Since: 0.1.0.0

server :: Text -> OAuth2Settings Handler Github OAuth2Result -> Text -> OAuth2Settings Handler Google OAuth2Result -> Routes (AsServerT Handler) Source #

Here we pull implement a very simple homepage, basically just showing the links to login, and connecting the two authGithub and authGoogle routes together. There's a bit of noise in passing all the relevant configs in, but this would go away in a "real" application, by passing that around in an env, or otherwise.

Since: 0.1.0.0

main :: IO () Source #

Entrypoint. The most important thing we do here is build our list of contexts by calling oauth2AuthHandler with the respective settings.

Since: 0.1.0.0