Ejemplo n.º 1
0
def get_oauth(token_endpoint: str, authorization_endpoint: str):
    port = get_open_port()
    redirect_uri = f'http://127.0.0.1:{port}/callback'
    oauth = OAuth2Session(CLIENT_ID,
                          redirect_uri=redirect_uri,
                          auto_refresh_url=token_endpoint,
                          scope=SCOPE)

    code_verifier = gen_code_verifier()
    code_challenge = gen_code_challenge(code_verifier)
    authorization_url, state = oauth.authorization_url(
        url=authorization_endpoint,
        code_challenge_method=CODE_CHALLENGE_METHOD,
        code_challenge=code_challenge)

    webbrowser.open(authorization_url)
    response = one_request(port, lets_connect=False)
    code = response['code'][0]
    assert (state == response['state'][0])
    token = oauth.fetch_token(token_url=token_endpoint,
                              code=code,
                              code_verifier=code_verifier,
                              client_id=oauth.client_id,
                              include_client_id=True)
    return oauth
Ejemplo n.º 2
0
def get_auth_url(oauth, code_verifier, auth_endpoint):
    """"
    generate a authorization URL.

    args:
        oauth (requests_oauthlib.OAuth2Session): oauth2 object
        code_verifier (str):
        auth_endpoint (str):
    """
    logger.info("Generating authorisation URL using auth endpoint {}".format(auth_endpoint))
    code_challenge_method = "S256"
    code_challenge = gen_code_challenge(code_verifier)
    authorization_url, state = oauth.authorization_url(auth_endpoint,
                                                       code_challenge_method=code_challenge_method,
                                                       code_challenge=code_challenge)
    return authorization_url, state
Ejemplo n.º 3
0
 def test_gen_code_challenge(self):
     gen_code_challenge('bla')