git.iko.soy/typeable/servant
on master help sign in
Replace `User` with `Account` in Generalized Authentication section (#757)

* Change `User` to `Account` in Generalized Authentication section

commitff5502f4f7a2646c5f07f5371d5491fce73abf69 authorRyan James Spencer <justanotherdot@users.noreply.github.com> dateTue 17 Oct 2017, 23:31 (9 years ago) parent6028062
1 file changed+17−14
doc/tutorial/Authentication.lhs+17−14
doc/tutorial/Authentication.lhs+17−14
@@ -245,25 +245,28 @@ your feedback!
245245
246246### What is Generalized Authentication?
247247
248−**TL;DR**: you throw a tagged `AuthProtect` combinator in front of the endpoints
249−you want protected and then supply a function `Request -> Handler user`
250−which we run anytime a request matches a protected endpoint. It precisely solves
251−the "I just need to protect these endpoints with a function that does some
252−complicated business logic" and nothing more. Behind the scenes we use a type
253−family instance (`AuthServerData`) and `Context` to accomplish this.
248+**TL;DR**: you throw a tagged `AuthProtect` combinator in front of the
249+endpoints you want protected and then supply a function `Request -> Handler a`,
250+where `a` is the type of your choice representing the data returned by
251+successful authentication - e.g., a `User` or, in our example below, `Account`.
252+This function is run anytime a request matches a protected endpoint. It
253+precisely solves the "I just need to protect these endpoints with a function
254+that does some complicated business logic" and nothing more. Behind the scenes
255+we use a type family instance (`AuthServerData`) and `Context` to accomplish
256+this.
254257
255258### Generalized Authentication in Action
256259
257260Let's implement a trivial authentication scheme. We will protect our API by
258261looking for a cookie named `"servant-auth-cookie"`. This cookie's value will
259−contain a key from which we can lookup a `User`.
262+contain a key from which we can lookup a `Account`.
260263
261264```haskell
262−-- | A user type that we "fetch from the database" after
265+-- | An account type that we "fetch from the database" after
263266-- performing authentication
264267newtype Account = Account { unAccount :: Text }
265268
266−-- | A (pure) database mapping keys to users.
269+-- | A (pure) database mapping keys to accounts.
267270database :: Map ByteString Account
268271database = fromList [ ("key1", Account "Anne Briggs")
269272 , ("key2", Account "Bruce Cockburn")
@@ -279,7 +282,7 @@ lookupAccount key = case Map.lookup key database of
279282```
280283
281284For generalized authentication, servant exposes the `AuthHandler` type,
282−which is used to wrap the `Request -> Handler user` logic. Let's
285+which is used to wrap the `Request -> Handler Account` logic. Let's
283286create a value of type `AuthHandler Request Account` using the above `lookupAccount`
284287method:
285288
@@ -377,13 +380,13 @@ forward:
377380
3783811. use the `AuthProtect` combinator to protect your API.
3793822. choose a application-specific data type used by your server when
380−authentication is successful (in our case this was `User`).
381−3. Create a value of `AuthHandler Request User` which encapsulates the
382−authentication logic (`Request -> Handler User`). This function
383+authentication is successful (in our case this was `Account`).
384+3. Create a value of `AuthHandler Request Account` which encapsulates the
385+authentication logic (`Request -> Handler Account`). This function
383386will be executed everytime a request matches a protected route.
3843874. Provide an instance of the `AuthServerData` type family, specifying your
385388application-specific data type returned when authentication is successful (in
386−our case this was `User`).
389+our case this was `Account`).
387390
388391Caveats:
389392