Skip to content

Commit

Permalink
version 0.1.3.8: allow service tokens (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
maksbotan authored Jun 23, 2021
1 parent bf91ba6 commit 87b2905
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.1.3.8] - 2021-06-22
### Added
- Possibility to accept Service Token in `OIDCAuth`. Token is considered a Service Token if it
lacks the `object_guid` claim. `preferred_username` claim is used as user id instead.

## [0.1.3.7] - 2021-06-10
### Added
- Add a way to describe fields in Swagger schemas.
Expand Down
8 changes: 7 additions & 1 deletion src/Web/Template/Servant/Auth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ data OIDCConfig
-- ^ cache - storing validation keys
, oidcDefaultExpiration :: NominalDiffTime
-- ^ Default expiration time for discovery document and JWKS
, oidcAllowServiceToken :: Bool
-- ^ Whether to accept service token (defined as "token without object_guid claim")
}

defaultOIDCCfg :: MonadIO m => m OIDCConfig
Expand All @@ -151,6 +153,7 @@ defaultOIDCCfg = do
, oidcIssuer = error "discovery uri not set"
, oidcClientId = error "client id not set"
, oidcDefaultExpiration = 10 * 60 -- 10 minutes
, oidcAllowServiceToken = False
}

instance ( HasServer api context
Expand Down Expand Up @@ -178,10 +181,13 @@ instance ( HasServer api context

claims <- getClaims cfg jwt jwkSet

let guid = claims ^? unregisteredClaims . ix "object_guid" . _String
let username = claims ^? unregisteredClaims . ix "preferred_username" . _String

uid <- maybe
(die ERROR unauth401 ("No object_guid found" :: Text))
return
$ claims ^? unregisteredClaims . ix "object_guid" . _String
(guid <|> (if oidcAllowServiceToken cfg then username else Nothing))

liftIO $ sequence_ $ catMaybes
[ userIdVaultKey <?> req <&> flip writeIORef (Just uid)
Expand Down
2 changes: 1 addition & 1 deletion web-template.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: web-template
version: 0.1.3.7
version: 0.1.3.8
synopsis: Web template
description:
Web template includes:
Expand Down

0 comments on commit 87b2905

Please sign in to comment.