Hi Sudheer,

Sending access token in headers works.
Here is the code section:

headers:

           Authorization: "Bearer {{ token_auth_response.json.access_token
}}"

           Content-Type: "application/json"


Thanks for your help.


Bikram

On Mon, Mar 18, 2019 at 11:48 AM bikram40 <[email protected]> wrote:

> Hi Sudheer,
>
> Here is the format of my tasks and it is working perfectly with curl
> command but I want to send data from variable as I mentioned earlier.
>
>
> - name: authenticate with restible via oauth2.0
>
>       uri:
>
>         body:
>
>           grant_type: client_credentials
>
>         body_format: form-urlencoded
>
>         force_basic_auth: yes
>
>         method: POST
>
>         user: "{{ client_id }}"
>
>         password: "{{ client_secret}}"
>
>         status_code: 201
>
>         url: https://gns-ansible-dev.corp.xxx.com:8443/auth/token
>
>         validate_certs: no
>
>       register: token_auth_response
>
>
>     - set_fact: access_token="{{ 'Authorization:'+'Bearer' + ' ' +
> token_auth_response.json.access_token }}"
>
>
>
>
>     - local_action: command curl -X PUT -i -H
> "Content-Type:application/json"
> https://gns-ansible-dev.corp.xxx.com:8443/api/job/{{ ticket }} -k --data
> '{"status":"complete","message":"unsuccessfully
> completed","actions":["close ticket"]}' --header  "{{ access_token }}"
>
>
>
> Thank you very much.
>
>
> Bikram
>
> On Sun, Mar 17, 2019 at 11:49 PM Sudheer Satyanarayana <
> [email protected]> wrote:
>
>>
>> On 17/03/19 9:43 PM, bikram40 wrote:
>> > Thanks for your feedback.
>> >
>> > But there is a problem in 'URI' module.
>> > In "URI" module, there is no way to pass "access token". Access token
>> > is required here as the url is OAUTH2.0 enabled.
>> >
>> > You can get access token by passing client id and secret but you
>> > cannot pass it to uri module to get the response back. That's why I am
>> > trying to use curl command and sending the JSON body.
>>
>> Something seems off here.
>>
>> I don't see how are you are passing 'access_token' in your curl command
>> line example.
>>
>> You can send 'access_token' via URI module in request body, header or URL.
>>
>> -
>>
>> Sudheer S
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/be015628-d567-2ef2-0150-661008594503%40techchorus.net
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAEFfMJT2%3D2eZ9oC-R5aQ5zD3AGcyGOmN9bBDWyGY_q7WbOqJFg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to