(code)
return encoded_jwt
Fetch a JSON Web Token (JWT) using a authentication code.

    Args:
        code: Authentication code obtained from an OAuth2 flow.

    Raises:
        JwtFetchError if JWT cannot be fetched.

    Returns:
        Encoded JWT.
Fetch a JSON Web Token (JWT) using a authentication code.
Fetch a JSON Web Token ( JWT ) using a authentication code .
def get_encoded_jwt_over_https(code):
    """Fetch a JSON Web Token (JWT) using a authentication code.

    Args:
        code: Authentication code obtained from an OAuth2 flow.

    Raises:
        JwtFetchError if JWT cannot be fetched.

    Returns:
        Encoded JWT.
    """

    discovery_document = get_oauth2_discovery_document()
    redirect_uri = url_for(
        'user_views.google_openid_connect',
        _scheme='https',
        _external=True
    )
    post_data = {
        'code': code,
        'client_id': current_app.config.get('GOOGLE_OIDC_CLIENT_ID'),
        'client_secret': current_app.config.get('GOOGLE_OIDC_CLIENT_SECRET'),
        'redirect_uri': redirect_uri,
        'grant_type': 'authorization_code'
    }
    token_url = discovery_document.get('token_endpoint')
    try:
        response = requests.post(token_url, data=post_data)
        encoded_jwt = response.json().get('id_token')
    except requests.exceptions.RequestException as e:
        raise JwtFetchError(
            'Cannot fetch JWT: {}'.format(e)) from e
    if response.status_code != HTTP_STATUS_CODE_OK:
        raise JwtFetchError(
            'Cannot fetch JWT: {}'.format(response.status_code))

    if not encoded_jwt:
        raise JwtFetchError('Cannot fetch JWT: Missing id_token in response')

    return encoded_jwt
def get_encoded_jwt_over_https ( code ) : discovery_document = get_oauth2_discovery_document ( ) redirect_uri = url_for ( 'user_views.google_openid_connect' , _scheme = 'https' , _external = True ) post_data = { 'code' : code , 'client_id' : current_app . config . get ( 'GOOGLE_OIDC_CLIENT_ID' ) , 'client_secret' : current_app . config . get ( 'GOOGLE_OIDC_CLIENT_SECRET' ) , 'redirect_uri' : redirect_uri , 'grant_type' : 'authorization_code' } token_url = discovery_document . get ( 'token_endpoint' ) try : response = requests . post ( token_url , data = post_data ) encoded_jwt = response . json ( ) . get ( 'id_token' ) except requests . exceptions . RequestException as e : raise JwtFetchError ( 'Cannot fetch JWT: {}' . format ( e ) ) from e if response . status_code != HTTP_STATUS_CODE_OK : raise JwtFetchError ( 'Cannot fetch JWT: {}' . format ( response . status_code ) ) if not encoded_jwt : raise JwtFetchError ( 'Cannot fetch JWT: Missing id_token in response' ) return encoded_jwt