async-refresh-tokens: Package implementing core logic for refreshing of expiring access tokens

[ bsd3, control, library ] [ Propose Tags ] [ Report a vulnerability ]

This package can be used for renewal of expiring access tokens according to user-provided actions. Tokens will be stored in a transactional variable (TVar).


[Skip to Readme]

Modules

[Last Documentation]

  • Control
    • Concurrent
      • Async
        • Refresh
          • Control.Concurrent.Async.Refresh.Tokens

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0, 0.2.0.0, 0.3.0.0, 0.3.0.1, 0.4.0.0
Dependencies async-refresh, base (>=4.7 && <5), bytestring, formatting, lens, lifted-async, monad-control, monad-logger, safe-exceptions, stm, text [details]
License BSD-3-Clause
Copyright (c) 2017 Moritz Schulte
Author Moritz Schulte
Maintainer mtesseract@silverratio.net
Category Control
Home page https://github.com/mtesseract/async-refresh-tokens#readme
Source repo head: git clone https://github.com/mtesseract/async-refresh-tokens
Uploaded by mtesseract at 2017-04-11T14:36:04Z
Distributions LTSHaskell:0.4.0.0, NixOS:0.4.0.0, Stackage:0.4.0.0
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 4164 total (26 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2017-04-11 [all 2 reports]

Readme for async-refresh-tokens-0.1.0

[back to package description]

async-refresh-tokens

About

This is Haskell library built on top of the async-refresh package implementing the logic for refreshing of expiring access tokens.

Usage

  • Create new token types. Using the DataKinds extension we can do this via data MyAppTokens = TokenFoo | TokenBar.

  • Make the tokens be instances of the IsToken type classes by defining the tokenScopes method and (optionally) tokenName (a human readable label for this token).

  • Create new token stores (which are basically TVar's containing the tokens wrapped in Either SomeException) using newEmptyTokenStore`.

  • Create a new configuration by adjusting defaultTokenConf using the functions tokenConfAddRequest and tokenConfSetFactor. The function tokenConfAddRequest expects values of type RequestToken — these values encapsulate the token stores together with a token-refreshing action.

  • Use newTokenRefresher to initiate token refreshing for each registered token refreshing request.

Example

{-# LANGUAGE DataKinds           #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE PolyKinds           #-}

data MyAppTokens = TokenFoo | TokenBar

instance IsToken 'TokenFoo where
  tokenScopes _ = ["foo.read", "foo.write"]

createTokenStoreFoo :: IO (TokenStore 'TokenFoo)
createTokenStoreFoo = runStderrLoggingT $ do
  tokenFoo <- newEmptyTokenStore (Proxy :: Proxy 'TokenFoo)
  let conf = defaultTokenConf
             & tokenConfAddRequest (RequestToken tokenFoo actionFoo)
  _ <- newTokenRefresher conf
  return tokenFoo

  where actionFoo :: (MonadIO m, IsToken t) => m (RefreshResult (Token t))
        actionFoo =
          return $ RefreshResult (Token "secret-foo-token") Nothing