Giter VIP home page Giter VIP logo

servant-oauth-server's Introduction

servant-oauth-server

This library consists of to main components: a Servant API combinator for bearer token authentication on resource servers, and a token endpoint for authorization servers. Access tokens are self-encoded using JWT. See haddocks for detailed API reference.

Resource Servers

To protect an API and require a given claims set, use AuthRequired claims :> api which will require a valid token and capture its claims (the endpoint will be a function from the claims to the wrapped endpoint, as with other parameters). The required claims must implement FromJWT, which provides a default instance for sub claims. For endpoints with mixed public and private content, use AuthOptional instead of AuthRequired, which will also accept no authorization header (although an invalid token will still cause an error response) and capture Nothing if given such a request. This is distinct from AuthRequired (Maybe claims), which still requires a valid token but will accept one without any specific claims.

Token Endpoint

The other part of this library is a set of functions for defining token endpoints, with the aim of making the case of a backend for a first-party SPA or mobile app as simple as possible. Creating a token endpoint requires a grant type and an action to verify those grants and return claims (or throw an error for invalid grants). Standard grants (and their parsing instances) are defined in Servant.OAuth.Grants. For endpoints which use a single type of grant, these can be used directly, or they used in a custom sum type, with parsers combined using <|>.

If refresh tokens are to be used, the validation action must also return a boolean indicating whether a refresh token is to be created with the request. The endpoint wrapper must additionally be given an action to create and store an opaque refresh token, which must be recognized later by the validation action.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.