oauth2_client/fetcher.py
def expiry_date(raw_token):
    """
    Determine token's expiry date if available. The RFC isn't strict about this,
    so aren't we. JWT Bearer grant type doesn't return expiration info at all.

    The preference of the source of this data is:
        1. `expires_in`, interpreted as seconds from now
        2. `expires_at`, interpreted as a timestamp from epoch in UTC

    From RFC:
        > expires_in
        >   RECOMMENDED.  The lifetime in seconds of the access token.  For
        >   example, the value "3600" denotes that the access token will
        >   expire in one hour from the time the response was generated.
        >   If omitted, the authorization server SHOULD provide the
        >   expiration time via other means or document the default value.
        Source: https://tools.ietf.org/html/rfc6749#section-4.2.2

    This is not critical, worst case we will just refresh the token too often.
    Hence the best-effort approach.

    Args:
        raw_token (dict):

    Returns:
        datetime: a timezone-aware datetime object or None

    Raises:
        ValueError: when received token already expired
    """
    if 'expires_in' in raw_token:
        expires = timezone.now() + timedelta(seconds=raw_token['expires_in'])
    elif 'expires_at' in raw_token:
        expires = float_to_datetime(raw_token['expires_at'], tzinfo=pytz.UTC)
    else:
        expires = None

    if expires and expires <= timezone.now():
        raise ValueError(
            'Received token already expired. This means either parsing issue on our side or auth '
            'provider gone insane. Received token: {}'.format(raw_token)
        )

    return expires

    Determine token's expiry date if available. The RFC isn't strict about this,
    so aren't we. JWT Bearer grant type doesn't return expiration info at all.

    The preference of the source of this data is:
        1. `expires_in`, interpreted as seconds from now
        2. `expires_at`, interpreted as a timestamp from epoch in UTC

    From RFC:
        > expires_in
        >   RECOMMENDED.  The lifetime in seconds of the access token.  For
        >   example, the value "3600" denotes that the access token will
        >   expire in one hour from the time the response was generated.
        >   If omitted, the authorization server SHOULD provide the
        >   expiration time via other means or document the default value.
        Source: https://tools.ietf.org/html/rfc6749#section-4.2.2

    This is not critical, worst case we will just refresh the token too often.
    Hence the best-effort approach.

    Args:
        raw_token (dict):

    Returns:
        datetime: a timezone-aware datetime object or None

    Raises:
        ValueError: when received token already expired
    
Determine token's expiry date if available. The RFC isn't strict about this,
so aren't we. JWT Bearer grant type doesn't return expiration info at all.

The preference of the source of this data is:
1. `expires_in`, interpreted as seconds from now
2. `expires_at`, interpreted as a timestamp from epoch in UTC

From RFC:
> expires_in
>   RECOMMENDED.  The lifetime in seconds of the access token.  For
>   example, the value "3600" denotes that the access token will
>   expire in one hour from the time the response was generated.
>   If omitted, the authorization server SHOULD provide the
>   expiration time via other means or document the default value.

This is not critical, worst case we will just refresh the token too often.
Hence the best-effort approach.
Determine token ' s expiry date if available . The RFC isn ' t strict about this so aren ' t we . JWT Bearer grant type doesn ' t return expiration info at all . The preference of the source of this data is : 1 . ` expires_in ` interpreted as seconds from now 2 . ` expires_at ` interpreted as a timestamp from epoch in UTC From RFC : > expires_in > RECOMMENDED . The lifetime in seconds of the access token . For > example the value " 3600 " denotes that the access token will > expire in one hour from the time the response was generated . > If omitted the authorization server SHOULD provide the > expiration time via other means or document the default value . This is not critical worst case we will just refresh the token too often . Hence the best - effort approach .
def expiry_date(raw_token):
    if 'expires_in' in raw_token:
        expires = timezone.now() + timedelta(seconds=raw_token['expires_in'])
    elif 'expires_at' in raw_token:
        expires = float_to_datetime(raw_token['expires_at'], tzinfo=pytz.UTC)
    else:
        expires = None
    if expires and expires <= timezone.now():
        raise ValueError(
            'Received token already expired. This means either parsing issue on our side or auth '
            'provider gone insane. Received token: {}'.format(raw_token)
        )
    return expires
def expiry_date ( raw_token ) : if 'expires_in' in raw_token : expires = timezone . now ( ) + timedelta ( seconds = raw_token [ 'expires_in' ] ) elif 'expires_at' in raw_token : expires = float_to_datetime ( raw_token [ 'expires_at' ] , tzinfo = pytz . UTC ) else : expires = None if expires and expires <= timezone . now ( ) : raise ValueError ( 'Received token already expired. This means either parsing issue on our side or auth ' 'provider gone insane. Received token: {}' . format ( raw_token ) ) return expires
Determine token's expiry date if available.
Determine token ' s expiry date if available .
"""
    Determine token's expiry date if available. The RFC isn't strict about this,
    so aren't we. JWT Bearer grant type doesn't return expiration info at all.

    The preference of the source of this data is:
        1. `expires_in`, interpreted as seconds from now
        2. `expires_at`, interpreted as a timestamp from epoch in UTC

    From RFC:
        > expires_in
        >   RECOMMENDED.  The lifetime in seconds of the access token.  For
        >   example, the value "3600" denotes that the access token will
        >   expire in one hour from the time the response was generated.
        >   If omitted, the authorization server SHOULD provide the
        >   expiration time via other means or document the default value.
        Source: https://tools.ietf.org/html/rfc6749#section-4.2.2

    This is not critical, worst case we will just refresh the token too often.
    Hence the best-effort approach.

    Args:
        raw_token (dict):

    Returns:
        datetime: a timezone-aware datetime object or None

    Raises:
        ValueError: when received token already expired
    """
a timezone-aware datetime object or None
a timezone - aware datetime object or None
datetime
when received token already expired
when received token already expired
ValueError
raw_token
None