ó
O'—^c           @@ s‚   d  Z  d d l m Z m Z d d l Z d d l m Z d d l m Z d d l	 m
 Z
 d d	 l	 m Z d
 e f d „  ƒ  YZ d S(   uš   
oauthlib.oauth2.rfc6749
~~~~~~~~~~~~~~~~~~~~~~~

This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
i    (   t   absolute_importt   unicode_literalsN(   t
   to_unicodei   (   t   Clienti   (   t   prepare_token_request(   t   parse_token_responset   ServiceApplicationClientc        
   B@ sM   e  Z d  Z d Z d d d d d „ Z d d d d d d d d d d „	 Z RS(   uç  A public client utilizing the JWT bearer grant.

    JWT bearer tokes can be used to request an access token when a client
    wishes to utilize an existing trust relationship, expressed through the
    semantics of (and digital signature or keyed message digest calculated
    over) the JWT, without a direct user approval step at the authorization
    server.

    This grant type does not involve an authorization step. It may be
    used by both public and confidential clients.
    u+   urn:ietf:params:oauth:grant-type:jwt-bearerc         K@ sA   t  t |  ƒ j | |  | |  _ | |  _ | |  _ | |  _ d S(   ub  Initalize a JWT client with defaults for implicit use later.

        :param client_id: Client identifier given by the OAuth provider upon
                          registration.

        :param private_key: Private key used for signing and encrypting.
                            Must be given as a string.

        :param subject: The principal that is the subject of the JWT, i.e. 
                        which user is the token requested on behalf of.
                        For example, ``foo@example.com.

        :param issuer: The JWT MUST contain an "iss" (issuer) claim that
                       contains a unique identifier for the entity that issued
                       the JWT. For example, ``your-client@provider.com``. 

        :param audience: A value identifying the authorization server as an
                         intended audience, e.g.
                         ``https://provider.com/oauth2/token``.

        :param kwargs: Additional arguments to pass to base client, such as
                       state and token. See Client.__init__.__doc__ for 
                       details.
        N(   t   superR   t   __init__t   private_keyt   subjectt   issuert   audience(   t   selft	   client_idR	   R
   R   R   t   kwargs(    (    sU   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth2/rfc6749/clients/service_application.pyR   #   s
    			u    c
      	   K@ sj  d d l  } | p |  j } | s0 t d ƒ ‚ n  i | p? |  j d 6| pO |  j d 6| p_ |  j d 6t | py t j ƒ  d ƒ d 6t | p’ t j ƒ  ƒ d	 6} x1 d D]) } | | d k r£ t d
 | ƒ ‚ q£ q£ Wd |
 k rò |
 j d ƒ | d <n  d |
 k r|
 j d ƒ | d <n  | j | p#i  ƒ | j	 | | d ƒ } t
 | ƒ } t |  j d | d | d |	 |
 S(   uê
  Create and add a JWT assertion to the request body.

        :param private_key: Private key used for signing and encrypting.
                            Must be given as a string.

        :param subject: (sub) The principal that is the subject of the JWT,
                        i.e.  which user is the token requested on behalf of.
                        For example, ``foo@example.com.

        :param issuer: (iss) The JWT MUST contain an "iss" (issuer) claim that
                       contains a unique identifier for the entity that issued
                       the JWT. For example, ``your-client@provider.com``. 

        :param audience: (aud) A value identifying the authorization server as an
                         intended audience, e.g.
                         ``https://provider.com/oauth2/token``.

        :param expires_at: A unix expiration timestamp for the JWT. Defaults
                           to an hour from now, i.e. ``time.time() + 3600``.

        :param issued_at: A unix timestamp of when the JWT was created.
                          Defaults to now, i.e. ``time.time()``.

        :param not_before: A unix timestamp after which the JWT may be used.
                           Not included unless provided.

        :param jwt_id: A unique JWT token identifier. Not included unless
                       provided.

        :param extra_claims: A dict of additional claims to include in the JWT.

        :param scope: The scope of the access request.

        :param body: Request body (string) with extra parameters.

        :param kwargs: Extra credentials to include in the token request.

        The "scope" parameter may be used, as defined in the Assertion
        Framework for OAuth 2.0 Client Authentication and Authorization Grants
        [I-D.ietf-oauth-assertions] specification, to indicate the requested
        scope.

        Authentication of the client is optional, as described in 
        `Section 3.2.1`_ of OAuth 2.0 [RFC6749] and consequently, the
        "client_id" is only needed when a form of client authentication that
        relies on the parameter is used.

        The following non-normative example demonstrates an Access Token
        Request with a JWT as an authorization grant (with extra line breaks
        for display purposes only):

        .. code-block: http

            POST /token.oauth2 HTTP/1.1
            Host: as.example.com
            Content-Type: application/x-www-form-urlencoded

            grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer
            &assertion=eyJhbGciOiJFUzI1NiJ9.
            eyJpc3Mi[...omitted for brevity...].
            J9l-ZhwP[...omitted for brevity...]

        .. _`Section 3.2.1`: http://tools.ietf.org/html/rfc6749#section-3.2.1
        i    Nu>   An encryption key must be supplied to make JWT token requests.u   issu   audu   subi  u   expu   iatu)   Claim must include %s but none was given.u
   not_beforeu   nbfu   jwt_idu   jtiu   RS256t   bodyt	   assertiont   scope(   u   issu   audu   sub(   t   jwtR	   t
   ValueErrorR   t   intt   timet   Nonet   popt   updatet   encodeR   R   t
   grant_type(   R   R	   R
   R   R   t
   expires_att	   issued_att   extra_claimsR   R   R   R   t   keyt   claimt   attrR   (    (    sU   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth2/rfc6749/clients/service_application.pyt   prepare_request_bodyC   s4    KN(   t   __name__t
   __module__t   __doc__R   R   R   R"   (    (    (    sU   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth2/rfc6749/clients/service_application.pyR      s   	 (   R%   t
   __future__R    R   R   t   oauthlib.commonR   t   baseR   t
   parametersR   R   R   (    (    (    sU   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth2/rfc6749/clients/service_application.pyt   <module>   s   