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

    It is attempting to connect to a localhost port instead of

    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:


    (most recent call last):
      File "f:/codefundo2019/voting-system-blockchain/contractsShobhit/python/", line 8, in <module>
        token = context.acquire_token_with_username_password(resource='',username="",password="Alonso123",client_id=client_id)
      File "C:\Users\SHOBHIT KUMAR.SHOBHIT-PC.000\.conda\envs\test\lib\site-packages\adal\", 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\", line 128, in _acquire_token
        return token_func(self)
      File "C:\Users\SHOBHIT KUMAR.SHOBHIT-PC.000\.conda\envs\test\lib\site-packages\adal\", 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\", 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\", 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\", 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\", 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":""}

    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 so that i could start the dev seamlessly.


    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