packages feed

planb-token-introspection 0.1.1.0 → 0.1.2.0

raw patch · 5 files changed

+28/−26 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Network.PlanB.Introspection: IntrospectionDeserialization :: Text -> ByteString -> IntrospectionException
- Network.PlanB.Introspection: IntrospectionEndpointMissing :: IntrospectionException
- Network.PlanB.Introspection: IntrospectionError :: PlanBError -> IntrospectionException
- Network.PlanB.Introspection.Internal: IntrospectionDeserialization :: Text -> ByteString -> IntrospectionException
- Network.PlanB.Introspection.Internal: IntrospectionEndpointMissing :: IntrospectionException
- Network.PlanB.Introspection.Internal: IntrospectionError :: PlanBError -> IntrospectionException
- Network.PlanB.Introspection.Internal.Types: IntrospectionDeserialization :: Text -> ByteString -> IntrospectionException
- Network.PlanB.Introspection.Internal.Types: IntrospectionEndpointMissing :: IntrospectionException
- Network.PlanB.Introspection.Internal.Types: IntrospectionError :: PlanBError -> IntrospectionException
- Network.PlanB.Introspection.Internal.Types: PlanBError :: Text -> Maybe Text -> Maybe Text -> Maybe Text -> PlanBError
- Network.PlanB.Introspection.Internal.Types: [oauth2ErrorDescription] :: PlanBError -> Maybe Text
- Network.PlanB.Introspection.Internal.Types: [oauth2ErrorState] :: PlanBError -> Maybe Text
- Network.PlanB.Introspection.Internal.Types: [oauth2ErrorURI] :: PlanBError -> Maybe Text
- Network.PlanB.Introspection.Internal.Types: [oauth2Error] :: PlanBError -> Text
- Network.PlanB.Introspection.Internal.Types: data PlanBError
- Network.PlanB.Introspection.Internal.Types: instance Data.Aeson.Types.FromJSON.FromJSON Network.PlanB.Introspection.Internal.Types.PlanBError
- Network.PlanB.Introspection.Internal.Types: instance Data.Aeson.Types.ToJSON.ToJSON Network.PlanB.Introspection.Internal.Types.PlanBError
- Network.PlanB.Introspection.Internal.Types: instance GHC.Classes.Eq Network.PlanB.Introspection.Internal.Types.PlanBError
- Network.PlanB.Introspection.Internal.Types: instance GHC.Generics.Generic Network.PlanB.Introspection.Internal.Types.PlanBError
- Network.PlanB.Introspection.Internal.Types: instance GHC.Show.Show Network.PlanB.Introspection.Internal.Types.PlanBError
+ Network.PlanB.Introspection: DeserializationFailure :: Text -> ByteString -> IntrospectionException
+ Network.PlanB.Introspection: ErrorResponse :: Text -> Maybe Text -> ErrorResponse
+ Network.PlanB.Introspection: InvalidRequest :: ErrorResponse -> IntrospectionException
+ Network.PlanB.Introspection: InvalidToken :: ErrorResponse -> IntrospectionException
+ Network.PlanB.Introspection: NoEndpoint :: IntrospectionException
+ Network.PlanB.Introspection: Other :: ErrorResponse -> IntrospectionException
+ Network.PlanB.Introspection: [errorResponseErrorDescription] :: ErrorResponse -> Maybe Text
+ Network.PlanB.Introspection: [errorResponseError] :: ErrorResponse -> Text
+ Network.PlanB.Introspection: data ErrorResponse
+ Network.PlanB.Introspection.Internal: DeserializationFailure :: Text -> ByteString -> IntrospectionException
+ Network.PlanB.Introspection.Internal: ErrorResponse :: Text -> Maybe Text -> ErrorResponse
+ Network.PlanB.Introspection.Internal: InvalidRequest :: ErrorResponse -> IntrospectionException
+ Network.PlanB.Introspection.Internal: InvalidToken :: ErrorResponse -> IntrospectionException
+ Network.PlanB.Introspection.Internal: NoEndpoint :: IntrospectionException
+ Network.PlanB.Introspection.Internal: Other :: ErrorResponse -> IntrospectionException
+ Network.PlanB.Introspection.Internal: [errorResponseErrorDescription] :: ErrorResponse -> Maybe Text
+ Network.PlanB.Introspection.Internal: [errorResponseError] :: ErrorResponse -> Text
+ Network.PlanB.Introspection.Internal: data ErrorResponse
+ Network.PlanB.Introspection.Internal.Types: DeserializationFailure :: Text -> ByteString -> IntrospectionException
+ Network.PlanB.Introspection.Internal.Types: ErrorResponse :: Text -> Maybe Text -> ErrorResponse
+ Network.PlanB.Introspection.Internal.Types: InvalidRequest :: ErrorResponse -> IntrospectionException
+ Network.PlanB.Introspection.Internal.Types: InvalidToken :: ErrorResponse -> IntrospectionException
+ Network.PlanB.Introspection.Internal.Types: NoEndpoint :: IntrospectionException
+ Network.PlanB.Introspection.Internal.Types: Other :: ErrorResponse -> IntrospectionException
+ Network.PlanB.Introspection.Internal.Types: [errorResponseErrorDescription] :: ErrorResponse -> Maybe Text
+ Network.PlanB.Introspection.Internal.Types: [errorResponseError] :: ErrorResponse -> Text
+ Network.PlanB.Introspection.Internal.Types: data ErrorResponse
+ Network.PlanB.Introspection.Internal.Types: instance Data.Aeson.Types.FromJSON.FromJSON Network.PlanB.Introspection.Internal.Types.ErrorResponse
+ Network.PlanB.Introspection.Internal.Types: instance Data.Aeson.Types.ToJSON.ToJSON Network.PlanB.Introspection.Internal.Types.ErrorResponse
+ Network.PlanB.Introspection.Internal.Types: instance GHC.Classes.Eq Network.PlanB.Introspection.Internal.Types.ErrorResponse
+ Network.PlanB.Introspection.Internal.Types: instance GHC.Generics.Generic Network.PlanB.Introspection.Internal.Types.ErrorResponse
+ Network.PlanB.Introspection.Internal.Types: instance GHC.Show.Show Network.PlanB.Introspection.Internal.Types.ErrorResponse
- Network.PlanB.Introspection: newWithManager :: (MonadThrow m, MonadIO m) => Maybe Manager -> Text -> m (TokenIntrospector m)
+ Network.PlanB.Introspection: newWithManager :: (MonadThrow m, MonadIO m) => Manager -> Text -> m (TokenIntrospector m)
- Network.PlanB.Introspection.Internal: newWithManager :: (MonadThrow m, MonadIO m) => Maybe Manager -> Text -> m (TokenIntrospector m)
+ Network.PlanB.Introspection.Internal: newWithManager :: (MonadThrow m, MonadIO m) => Manager -> Text -> m (TokenIntrospector m)

Files

planb-token-introspection.cabal view
@@ -1,5 +1,5 @@ name:                planb-token-introspection-version:             0.1.1.0+version:             0.1.2.0 synopsis:            Token Introspection for PlanB description:         This package provides token introspection functionality                      for the PlanB token provider.
src/Network/PlanB/Introspection.hs view
@@ -2,6 +2,7 @@   ( TokenInfo(..)   , Conf   , IntrospectionException(..)+  , ErrorResponse(..)   , new   , newWithManager   , newFromEnv
src/Network/PlanB/Introspection/Internal.hs view
@@ -6,6 +6,7 @@   ( TokenInfo(..)   , Conf   , IntrospectionException(..)+  , ErrorResponse(..)   , new   , newWithManager   , newFromEnv@@ -36,17 +37,15 @@ new :: (MonadThrow m, MonadIO m)     => Text     -> m (TokenIntrospector m)-new = newWithManager Nothing+new = newWithBackend (backendIO Nothing)  -- | Create a new PlanB introspector using the provided endpoint and -- manager. newWithManager :: (MonadThrow m, MonadIO m)-               => Maybe Manager+               => Manager                -> Text                -> m (TokenIntrospector m)-newWithManager maybeManager endpoint = do-  conf <- newConf (backendIO maybeManager) endpoint-  pure $ TokenIntrospector { introspectToken = introspectTokenImpl conf }+newWithManager manager = newWithBackend (backendIO (Just manager))  backendIO :: MonadIO m           => Maybe Manager@@ -83,7 +82,7 @@       BackendEnv { .. } = backendEnv backend   endpoint <- envLookup "PLANB_INTROSPECTION_ENDPOINT" >>= \ case     Just ep -> pure ep-    Nothing -> throwM IntrospectionEndpointMissing+    Nothing -> throwM NoEndpoint   newWithBackend backend endpoint  -- | Create a new PlanB introspector using the provided backend and endpoint.@@ -128,10 +127,7 @@       request     = endpoint { method         = "GET"                              , path           = "/oauth2/tokeninfo"                              , requestHeaders = [("Authorization", bearerToken)] }-      httpBackend = conf-                    & confBackend-                    & backendHttp-  response <- httpRequestExecute httpBackend request+  response <- httpRequestExecute request   let body = responseBody response & ByteString.Lazy.toStrict    when (statusCode (responseStatus response) /= 200) $@@ -141,14 +137,20 @@     Right tokenInfo ->       pure tokenInfo     Left errMsg ->-      throwM $ IntrospectionDeserialization (Text.pack errMsg) body+      throwM $ DeserializationFailure (Text.pack errMsg) body +  where backend = conf & confBackend+        BackendHttp { .. } = backend & backendHttp+ bodyToPlanBException   :: ByteString -> IntrospectionException bodyToPlanBException bytes =   case eitherDecodeStrict bytes of-    Right err ->-      IntrospectionError err+    Right err @ ErrorResponse { .. } ->+      case errorResponseError of+        "invalid_token"   -> InvalidToken err+        "invalid_request" -> InvalidRequest err+        _                 -> Other err     Left errMsgStr  ->       let errMsg = Text.pack errMsgStr-      in IntrospectionDeserialization errMsg bytes+      in DeserializationFailure errMsg bytes
src/Network/PlanB/Introspection/Internal/Types.hs view
@@ -49,19 +49,18 @@   { confIntrospectionRequest :: Request   , confBackend              :: Backend m } --- | Type for RFC7807 @Problem@ objects.-data PlanBError = PlanBError-  { oauth2Error            :: Text-  , oauth2ErrorDescription :: Maybe Text-  , oauth2ErrorURI         :: Maybe Text-  , oauth2ErrorState       :: Maybe Text+data ErrorResponse = ErrorResponse+  { errorResponseError            :: Text+  , errorResponseErrorDescription :: Maybe Text   } deriving (Show, Eq, Generic) -$(deriveJSON (aesonDrop (length ("oauth2" :: String)) snakeCase) ''PlanBError)+$(deriveJSON (aesonDrop (length ("errorResponse" :: String)) snakeCase) ''ErrorResponse) -data IntrospectionException = IntrospectionDeserialization Text ByteString-                            | IntrospectionError PlanBError-                            | IntrospectionEndpointMissing+data IntrospectionException = DeserializationFailure Text ByteString+                            | InvalidRequest ErrorResponse+                            | InvalidToken ErrorResponse+                            | Other ErrorResponse+                            | NoEndpoint   deriving (Typeable, Show)  instance Exception IntrospectionException
tests/Network/PlanB/Introspection/Internal/Test.hs view
@@ -48,7 +48,7 @@                   , _testStateEnvironment = Map.empty                   }       tokenName = "some-token-name"-  Left (PlanB.IntrospectionDeserialization _ _) <- try $ runTestStack testState $ do+  Left (PlanB.DeserializationFailure _ _) <- try $ runTestStack testState $ do     introspector <- makeTestIntrospector     void $ introspectToken introspector tokenName   pure ()