none
How do I acquire authentication bearer token for a particular user in the Blockchain Workbench? RRS feed

  • Question

  • I am not able to get the swagger_client to work for my application that is given here https://github.com/Azure-Samples/blockchain/tree/master/blockchain-workbench/rest-api-samples/python/

    It is attempting to connect to a localhost port instead of https://votemaadi-4bm4ew-api.azurewebsites.net

    So instead, I thought of acquiring a token bearer using adal and implementing my own API calls.

    using the following code, i was able to get an authentication bearer. But it wasn't for a particular user.

    context = adal.AuthenticationContext(authority_url,api_version=None) token = context.acquire_token_with_client_credentials(client_id,client_id,client_secret) api_client = ApiClient(); bearer_token = "Bearer "+token['accessToken'] api_client.set_default_header('Authorization',bearer_token) api_user = swagger_client.UsersApi(api_client) me = api_user.me_get() pprint(me)

    So i tried using the context.acquire_token_with_username_password() but was unable to figure out what is the resouce parameter.

    that gave the following error:

    Traceback

    (most recent call last):
      File "f:/codefundo2019/voting-system-blockchain/contractsShobhit/python/regVoter.py", line 8, in <module>
        token = context.acquire_token_with_username_password(resource='https://graph.windows.net',username="shobhit@kumarshobhit98outlook.onmicrosoft.com",password="Alonso123",client_id=client_id)
      File "C:\Users\SHOBHIT KUMAR.SHOBHIT-PC.000\.conda\envs\test\lib\site-packages\adal\authentication_context.py", line 164, in acquire_token_with_username_password
        return self._acquire_token(token_func)
      File "C:\Users\SHOBHIT KUMAR.SHOBHIT-PC.000\.conda\envs\test\lib\site-packages\adal\authentication_context.py", line 128, in _acquire_token
        return token_func(self)
      File "C:\Users\SHOBHIT KUMAR.SHOBHIT-PC.000\.conda\envs\test\lib\site-packages\adal\authentication_context.py", line 162, in token_func
        return token_request.get_token_with_username_password(username, password)
      File "C:\Users\SHOBHIT KUMAR.SHOBHIT-PC.000\.conda\envs\test\lib\site-packages\adal\token_request.py", line 281, in get_token_with_username_password
        token = self._get_token_username_password_managed(username, password)
      File "C:\Users\SHOBHIT KUMAR.SHOBHIT-PC.000\.conda\envs\test\lib\site-packages\adal\token_request.py", line 177, in _get_token_username_password_managed
        return self._oauth_get_token(oauth_parameters)
      File "C:\Users\SHOBHIT KUMAR.SHOBHIT-PC.000\.conda\envs\test\lib\site-packages\adal\token_request.py", line 112, in _oauth_get_token
        return client.get_token(oauth_parameters)
      File "C:\Users\SHOBHIT KUMAR.SHOBHIT-PC.000\.conda\envs\test\lib\site-packages\adal\oauth2_client.py", line 289, in get_token
        raise AdalError(return_error_string, error_response)
    adal.adal_error.AdalError: Get Token request returned http error: 401 and server response: {"error":"invalid_client","error_description":"AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.\r\nTrace ID: 8e877605-bd33-4e3b-87a4-515270952500\r\nCorrelation ID: 8de6a21b-b7ed-4249-9694-372db73f432d\r\nTimestamp: 2019-08-09 08:44:50Z","error_codes":[7000218],"timestamp":"2019-08-09 08:44:50Z","trace_id":"8e877605-bd33-4e3b-87a4-515270952500","correlation_id":"8de6a21b-b7ed-4249-9694-372db73f432d","error_uri":"https://login.microsoftonline.com/error?code=7000218"}

    I dont know why this asks for a client secret

    So, could I get help in the following?

    1. setting up the swagger_client given at https://github.com/Azure-Samples/blockchain/tree/master/blockchain-workbench/rest-api-samples/python/ so that i could start the dev seamlessly.

    OR

    2. usage of the acquire_token_with_username_password()

    I think option 1 would be much more easier in terms of devlopment.

    And I think my workbench application is all setup correctly as I am able to use the APIs on postman. (for this i am getting the bearer token using Inspect Element on a web browser after logging in)


    Friday, August 9, 2019 8:08 AM