Copyright | (C) 2025 Matthias Pall Gissurarson |
---|---|
License | MIT |
Maintainer | mpg@mpg.is |
Stability | experimental |
Portability | GHC |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
MCP.Server.Auth
Description
This module provides MCP-compliant OAuth 2.1 authentication with PKCE support.
Synopsis
- data OAuthConfig = OAuthConfig {
- oauthEnabled :: Bool
- oauthProviders :: [OAuthProvider]
- tokenValidationEndpoint :: Maybe Text
- requireHTTPS :: Bool
- authCodeExpirySeconds :: Int
- accessTokenExpirySeconds :: Int
- supportedScopes :: [Text]
- supportedResponseTypes :: [Text]
- supportedGrantTypes :: [Text]
- supportedAuthMethods :: [Text]
- supportedCodeChallengeMethods :: [Text]
- autoApproveAuth :: Bool
- demoUserIdTemplate :: Maybe Text
- demoEmailDomain :: Text
- demoUserName :: Text
- publicClientSecret :: Maybe Text
- authCodePrefix :: Text
- refreshTokenPrefix :: Text
- clientIdPrefix :: Text
- authorizationSuccessTemplate :: Maybe Text
- data OAuthProvider = OAuthProvider {}
- data OAuthGrantType
- data TokenInfo = TokenInfo {}
- validateBearerToken :: MonadIO m => OAuthConfig -> Text -> m (Either Text TokenInfo)
- extractBearerToken :: Text -> Maybe Text
- data PKCEChallenge = PKCEChallenge {}
- generateCodeVerifier :: IO Text
- generateCodeChallenge :: Text -> Text
- validateCodeVerifier :: Text -> Text -> Bool
- data OAuthMetadata = OAuthMetadata {
- issuer :: Text
- authorizationEndpoint :: Text
- tokenEndpoint :: Text
- registrationEndpoint :: Maybe Text
- userInfoEndpoint :: Maybe Text
- jwksUri :: Maybe Text
- scopesSupported :: Maybe [Text]
- responseTypesSupported :: [Text]
- grantTypesSupported :: Maybe [Text]
- tokenEndpointAuthMethodsSupported :: Maybe [Text]
- codeChallengeMethodsSupported :: Maybe [Text]
- discoverOAuthMetadata :: MonadIO m => Text -> m (Either String OAuthMetadata)
OAuth Configuration
data OAuthConfig Source #
OAuth configuration for the MCP server
Constructors
OAuthConfig | |
Fields
|
Instances
data OAuthProvider Source #
OAuth provider configuration (MCP-compliant)
Constructors
OAuthProvider | |
Fields
|
Instances
data OAuthGrantType Source #
OAuth grant types supported by MCP
Constructors
AuthorizationCode | |
ClientCredentials |
Instances
Generic OAuthGrantType Source # | |
Defined in MCP.Server.Auth Associated Types type Rep OAuthGrantType :: Type -> Type # Methods from :: OAuthGrantType -> Rep OAuthGrantType x # to :: Rep OAuthGrantType x -> OAuthGrantType # | |
Show OAuthGrantType Source # | |
Defined in MCP.Server.Auth Methods showsPrec :: Int -> OAuthGrantType -> ShowS # show :: OAuthGrantType -> String # showList :: [OAuthGrantType] -> ShowS # | |
Eq OAuthGrantType Source # | |
Defined in MCP.Server.Auth Methods (==) :: OAuthGrantType -> OAuthGrantType -> Bool # (/=) :: OAuthGrantType -> OAuthGrantType -> Bool # | |
type Rep OAuthGrantType Source # | |
Token Validation
Token introspection response
Constructors
TokenInfo | |
Instances
validateBearerToken :: MonadIO m => OAuthConfig -> Text -> m (Either Text TokenInfo) Source #
Validate a bearer token
PKCE Support
data PKCEChallenge Source #
PKCE challenge data
Constructors
PKCEChallenge | |
Fields
|
Instances
Generic PKCEChallenge Source # | |
Defined in MCP.Server.Auth Associated Types type Rep PKCEChallenge :: Type -> Type # | |
Show PKCEChallenge Source # | |
Defined in MCP.Server.Auth Methods showsPrec :: Int -> PKCEChallenge -> ShowS # show :: PKCEChallenge -> String # showList :: [PKCEChallenge] -> ShowS # | |
type Rep PKCEChallenge Source # | |
Defined in MCP.Server.Auth type Rep PKCEChallenge = D1 ('MetaData "PKCEChallenge" "MCP.Server.Auth" "mcp-0.3.0.0-inplace" 'False) (C1 ('MetaCons "PKCEChallenge" 'PrefixI 'True) (S1 ('MetaSel ('Just "codeVerifier") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "codeChallenge") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "challengeMethod") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)))) |
generateCodeVerifier :: IO Text Source #
Generate a cryptographically secure code verifier for PKCE
generateCodeChallenge :: Text -> Text Source #
Generate code challenge from verifier using SHA256 (S256 method)
Metadata Discovery
data OAuthMetadata Source #
OAuth metadata (from discovery endpoint)
Constructors
OAuthMetadata | |
Fields
|
Instances
discoverOAuthMetadata :: MonadIO m => Text -> m (Either String OAuthMetadata) Source #
Discover OAuth metadata from a well-known endpoint