-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | JSON Web Token (JWT) decoding and encoding
--   
--   JSON Web Token (JWT) is a compact URL-safe means of representing
--   claims to be transferred between two parties.
--   
--   To get started, see the documentation for the <a>Web.JWT</a> module.
@package jwt
@version 0.6.0


-- | This implementation of JWT is based on
--   <a>http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-30</a>
--   (Version 30) but currently only implements the minimum required to
--   work with the Atlassian Connect framework.
--   
--   Known limitations:
--   
--   <ul>
--   <li>Only HMAC SHA-256 algorithm is currently a supported signature
--   algorithm</li>
--   <li>There is currently no verification of time related information
--   (<a>exp</a>, <a>nbf</a>, <a>iat</a>).</li>
--   <li>Registered claims are not validated</li>
--   <li>This implementation uses the term <a>JWTHeader</a> instead of
--   <tt>JOSEHeader</tt> (changed in version 23 of the JWT draft). Future
--   versions will move to the offical term once that has stabilised.</li>
--   </ul>
module Web.JWT

-- | Decode a claims set without verifying the signature. This is useful if
--   information from the claim set is required in order to verify the
--   claim (e.g. the secret needs to be retrieved based on unverified
--   information from the claims set).
--   
--   <pre>
--   &gt;&gt;&gt; :{
--    let
--        input = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U" :: T.Text
--        mJwt = decode input
--    in fmap header mJwt
--   :}
--   Just (JWTHeader {typ = Just "JWT", cty = Nothing, alg = Just HS256})
--   </pre>
--   
--   and
--   
--   <pre>
--   &gt;&gt;&gt; :{
--    let
--        input = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U" :: T.Text
--        mJwt = decode input
--    in fmap claims mJwt
--   :}
--   Just (JWTClaimsSet {iss = Nothing, sub = Nothing, aud = Nothing, exp = Nothing, nbf = Nothing, iat = Nothing, jti = Nothing, unregisteredClaims = fromList [("some",String "payload")]})
--   </pre>
decode :: JSON -> Maybe (JWT UnverifiedJWT)

-- | Using a known secret and a decoded claims set verify that the
--   signature is correct and return a verified JWT token as a result.
--   
--   This will return a VerifiedJWT if and only if the signature can be
--   verified using the given secret.
--   
--   The separation between decode and verify is very useful if you are
--   communicating with multiple different services with different secrets
--   and it allows you to lookup the correct secret for the unverified JWT
--   before trying to verify it. If this is not an isuse for you (there
--   will only ever be one secret) then you should just use
--   <a>decodeAndVerifySignature</a>.
--   
--   <pre>
--   &gt;&gt;&gt; :{
--    let
--        input = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U" :: T.Text
--        mUnverifiedJwt = decode input
--        mVerifiedJwt = verify (secret "secret") =&lt;&lt; mUnverifiedJwt
--    in signature =&lt;&lt; mVerifiedJwt
--   :}
--   Just (Signature "Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U")
--   </pre>
verify :: Secret -> JWT UnverifiedJWT -> Maybe (JWT VerifiedJWT)

-- | Decode a claims set and verify that the signature matches by using the
--   supplied secret. The algorithm is based on the supplied header value.
--   
--   This will return a VerifiedJWT if and only if the signature can be
--   verified using the given secret.
--   
--   <pre>
--   &gt;&gt;&gt; :{
--    let
--        input = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U" :: T.Text
--        mJwt = decodeAndVerifySignature (secret "secret") input
--    in signature =&lt;&lt; mJwt
--   :}
--   Just (Signature "Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U")
--   </pre>
decodeAndVerifySignature :: Secret -> JSON -> Maybe (JWT VerifiedJWT)

-- | Encode a claims set using the given secret
--   
--   <pre>
--   &gt;&gt;&gt; :{
--    let
--        cs = def { -- def returns a default JWTClaimsSet
--           iss = stringOrURI "Foo"
--         , unregisteredClaims = Map.fromList [("http://example.com/is_root", (Bool True))]
--        }
--        key = secret "secret-key"
--    in encodeSigned HS256 key cs
--   :}
--   "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJodHRwOi8vZXhhbXBsZS5jb20vaXNfcm9vdCI6dHJ1ZSwiaXNzIjoiRm9vIn0.vHQHuG3ujbnBUmEp-fSUtYxk27rLiP2hrNhxpyWhb2E"
--   </pre>
encodeSigned :: Algorithm -> Secret -> JWTClaimsSet -> JSON

-- | Encode a claims set without signing it
--   
--   <pre>
--   &gt;&gt;&gt; :{
--    let
--        cs = def { -- def returns a default JWTClaimsSet
--        iss = stringOrURI "Foo"
--      , iat = intDate 1394700934
--      , unregisteredClaims = Map.fromList [("http://example.com/is_root", (Bool True))]
--    }
--    in encodeUnsigned cs
--   :}
--   "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjEzOTQ3MDA5MzQsImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlLCJpc3MiOiJGb28ifQ."
--   </pre>
encodeUnsigned :: JWTClaimsSet -> JSON

-- | Try to extract the value for the issue claim field <a>iss</a> from the
--   web token in JSON form
tokenIssuer :: JSON -> Maybe StringOrURI

-- | Create a Secret using the given key This will currently simply wrap
--   the given key appropriately buy may return a Nothing in the future if
--   the key needs to adhere to a specific format and the given key is
--   invalid.
secret :: Text -> Secret

-- | Extract the claims set from a JSON Web Token
claims :: JWT r -> JWTClaimsSet

-- | Extract the header from a JSON Web Token
header :: JWT r -> JWTHeader

-- | Extract the signature from a verified JSON Web Token
signature :: JWT r -> Maybe Signature

-- | Convert the <a>aud</a> claim in a <a>JWTClaimsSet</a> into a
--   `[StringOrURI]`
auds :: JWTClaimsSet -> [StringOrURI]

-- | Convert the <a>NominalDiffTime</a> into an IntDate. Returns a Nothing
--   if the argument is invalid (e.g. the NominalDiffTime must be
--   convertible into a positive Integer representing the seconds since
--   epoch).
intDate :: NominalDiffTime -> Maybe IntDate

-- | Convert a <a>Text</a> into a <a>StringOrURI</a>. Returns a Nothing if
--   the String cannot be converted (e.g. if the String contains a
--   <tt>:</tt> but is *not* a valid URI).
stringOrURI :: Text -> Maybe StringOrURI

-- | Convert a <a>StringOrURI</a> into a <a>Text</a>. Returns the T.Text
--   representing the String as-is or a Text representation of the URI
--   otherwise.
stringOrURIToText :: StringOrURI -> Text

-- | Return the seconds since 1970-01-01T0:0:0Z UTC for the given
--   <a>IntDate</a>
secondsSinceEpoch :: IntDate -> NominalDiffTime

-- | The typ (type) Header Parameter defined by [JWS] and [JWE] is used to
--   declare the MIME Media Type [IANA.MediaTypes] of this complete JWT in
--   contexts where this is useful to the application. This parameter has
--   no effect upon the JWT processing.
typ :: JWTHeader -> Maybe Text

-- | The cty (content type) Header Parameter defined by [JWS] and [JWE] is
--   used by this specification to convey structural information about the
--   JWT.
cty :: JWTHeader -> Maybe Text

-- | The alg (algorithm) used for signing the JWT. The HS256 (HMAC using
--   SHA-256) is the only required algorithm and the only one supported in
--   this implementation in addition to "none" which means that no
--   signature will be used.
--   
--   See
--   <a>http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-23#page-6</a>
alg :: JWTHeader -> Maybe Algorithm

-- | JSON Web Token without signature verification
data UnverifiedJWT

-- | JSON Web Token that has been successfully verified
data VerifiedJWT
data Signature

-- | The secret used for calculating the message signature
data Secret

-- | The JSON Web Token
data JWT r
type JSON = Text
data Algorithm

-- | HMAC using SHA-256 hash algorithm
HS256 :: Algorithm

-- | The JWT Claims Set represents a JSON object whose members are the
--   claims conveyed by the JWT.
data JWTClaimsSet
JWTClaimsSet :: Maybe StringOrURI -> Maybe StringOrURI -> Maybe (Either StringOrURI [StringOrURI]) -> Maybe IntDate -> Maybe IntDate -> Maybe IntDate -> Maybe StringOrURI -> ClaimsMap -> JWTClaimsSet

-- | The iss (issuer) claim identifies the principal that issued the JWT.
[iss] :: JWTClaimsSet -> Maybe StringOrURI

-- | The sub (subject) claim identifies the principal that is the subject
--   of the JWT.
[sub] :: JWTClaimsSet -> Maybe StringOrURI

-- | The aud (audience) claim identifies the audiences that the JWT is
--   intended for according to draft 18 of the JWT spec, the aud claim is
--   option and may be present in singular or as a list.
[aud] :: JWTClaimsSet -> Maybe (Either StringOrURI [StringOrURI])

-- | The exp (expiration time) claim identifies the expiration time on or
--   after which the JWT MUST NOT be accepted for processing. Its value
--   MUST be a number containing an IntDate value.
[exp] :: JWTClaimsSet -> Maybe IntDate

-- | The nbf (not before) claim identifies the time before which the JWT
--   MUST NOT be accepted for processing.
[nbf] :: JWTClaimsSet -> Maybe IntDate

-- | The iat (issued at) claim identifies the time at which the JWT was
--   issued.
[iat] :: JWTClaimsSet -> Maybe IntDate

-- | The jti (JWT ID) claim provides a unique identifier for the JWT.
[jti] :: JWTClaimsSet -> Maybe StringOrURI
[unregisteredClaims] :: JWTClaimsSet -> ClaimsMap
type ClaimsMap = Map Text Value

-- | A JSON numeric value representing the number of seconds from
--   1970-01-01T0:0:0Z UTC until the specified UTC date/time.
data IntDate

-- | A JSON string value, with the additional requirement that while
--   arbitrary string values MAY be used, any value containing a ":"
--   character MUST be a URI [RFC3986]. StringOrURI values are compared as
--   case-sensitive strings with no transformations or canonicalizations
--   applied.
data StringOrURI

-- | JWT Header, describes the cryptographic operations applied to the JWT
data JWTHeader
instance GHC.Classes.Eq Web.JWT.JWTClaimsSet
instance GHC.Show.Show Web.JWT.JWTClaimsSet
instance GHC.Show.Show Web.JWT.JWTHeader
instance GHC.Classes.Eq Web.JWT.JWTHeader
instance GHC.Show.Show Web.JWT.Algorithm
instance GHC.Classes.Eq Web.JWT.Algorithm
instance GHC.Classes.Eq Web.JWT.StringOrURI
instance GHC.Classes.Ord Web.JWT.IntDate
instance GHC.Classes.Eq Web.JWT.IntDate
instance GHC.Show.Show Web.JWT.IntDate
instance GHC.Show.Show Web.JWT.Signature
instance GHC.Show.Show (Web.JWT.JWT r)
instance GHC.Classes.Eq Web.JWT.Secret
instance GHC.Show.Show Web.JWT.Secret
instance GHC.Classes.Eq Web.JWT.Signature
instance GHC.Show.Show Web.JWT.StringOrURI
instance Data.Default.Class.Default Web.JWT.JWTHeader
instance Data.Default.Class.Default Web.JWT.JWTClaimsSet
instance Data.Aeson.Types.Class.ToJSON Web.JWT.JWTClaimsSet
instance Data.Aeson.Types.Class.FromJSON Web.JWT.JWTClaimsSet
instance Data.Aeson.Types.Class.FromJSON Web.JWT.JWTHeader
instance Data.Aeson.Types.Class.ToJSON Web.JWT.JWTHeader
instance Data.Aeson.Types.Class.ToJSON Web.JWT.IntDate
instance Data.Aeson.Types.Class.FromJSON Web.JWT.IntDate
instance Data.Aeson.Types.Class.ToJSON Web.JWT.Algorithm
instance Data.Aeson.Types.Class.FromJSON Web.JWT.Algorithm
instance Data.Aeson.Types.Class.ToJSON Web.JWT.StringOrURI
instance Data.Aeson.Types.Class.FromJSON Web.JWT.StringOrURI
