Adding an Authorization Bearer header via Zinc

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding an Authorization Bearer header via Zinc

Andy Burnett
I am building some pharo scripts to edit tasks in the Asana.com system.

I have generated a Personal Access Token, and the terminal command of:

curl -H "Authorization: Bearer 12345abc" https://app.asana.com/api/1.0/users/me

Returns 200/ok, and the right data.

However, the pharo commands

tmp1 := ZnClient new.
tmp1 headerAt: 'Authorization:' put: 'Bearer 12345abc'.
tmp1 get.

Results in an authorisation error. 

I haven't tried using Zinc to access authenticated sites before, what am I doing wrong?

Cheers
Andy
Reply | Threaded
Open this post in threaded view
|

Re: Adding an Authorization Bearer header via Zinc

Ben Coman
On Tue, 28 Aug 2018 at 02:25, Andy Burnett <[hidden email]> wrote:
I am building some pharo scripts to edit tasks in the Asana.com system.

I have generated a Personal Access Token, and the terminal command of:

curl -H "Authorization: Bearer 12345abc" https://app.asana.com/api/1.0/users/me

Returns 200/ok, and the right data.

However, the pharo commands

tmp1 := ZnClient new.
tmp1 headerAt: 'Authorization:' put: 'Bearer 12345abc'.
tmp1 get.

Results in an authorisation error. 

I haven't tried using Zinc to access authenticated sites before, what am I doing wrong?



HTH, cheers -ben
Reply | Threaded
Open this post in threaded view
|

Re: Adding an Authorization Bearer header via Zinc

Sven Van Caekenberghe-2
Have a look at

ZnClient>>#username:password:
ZnClient>>#setBasicAuthenticationUsername:password:

ZnRequest>>#setBasicAuthenticationUsername:password:
ZnRequest>>#setAuthorization:

and their senders. This should get you started. It is possible/probable that you have to set the #url: before you modify the headers (you can check that by inspecting the ZnClient object).

> On 27 Aug 2018, at 20:41, Ben Coman <[hidden email]> wrote:
>
> On Tue, 28 Aug 2018 at 02:25, Andy Burnett <[hidden email]> wrote:
> I am building some pharo scripts to edit tasks in the Asana.com system.
>
> I have generated a Personal Access Token, and the terminal command of:
>
> curl -H "Authorization: Bearer 12345abc" https://app.asana.com/api/1.0/users/me
>
> Returns 200/ok, and the right data.
>
> However, the pharo commands
>
> tmp1 := ZnClient new.
> tmp1 headerAt: 'Authorization:' put: 'Bearer 12345abc'.
> tmp1 url: 'https://app.asana.com/api/1.0/users/me'.
> tmp1 get.
>
> Results in an authorisation error.
>
> I haven't tried using Zinc to access authenticated sites before, what am I doing wrong?
>
>
> I just happen to have done this today...
> https://github.com/exercism/pharo/issues/32#issuecomment-416100875
>
> HTH, cheers -ben


Reply | Threaded
Open this post in threaded view
|

Re: Adding an Authorization Bearer header via Zinc

NorbertHartl
In reply to this post by Andy Burnett
You have a colon in the name of the header. I‘m not sure zinc removes it. It could be a problem.

Norbert

Am 27.08.2018 um 20:23 schrieb Andy Burnett <[hidden email]>:

I am building some pharo scripts to edit tasks in the Asana.com system.

I have generated a Personal Access Token, and the terminal command of:

curl -H "Authorization: Bearer 12345abc" https://app.asana.com/api/1.0/users/me

Returns 200/ok, and the right data.

However, the pharo commands

tmp1 := ZnClient new.
tmp1 headerAt: 'Authorization:' put: 'Bearer 12345abc'.
tmp1 get.

Results in an authorisation error. 

I haven't tried using Zinc to access authenticated sites before, what am I doing wrong?

Cheers
Andy
Reply | Threaded
Open this post in threaded view
|

Re: Adding an Authorization Bearer header via Zinc

Sven Van Caekenberghe-2
Duh. Yes, there should be not colon at the end of the header name.

> On 27 Aug 2018, at 21:12, Norbert Hartl <[hidden email]> wrote:
>
> You have a colon in the name of the header. I‘m not sure zinc removes it. It could be a problem.
>
> Norbert
>
> Am 27.08.2018 um 20:23 schrieb Andy Burnett <[hidden email]>:
>
>> I am building some pharo scripts to edit tasks in the Asana.com system.
>>
>> I have generated a Personal Access Token, and the terminal command of:
>>
>> curl -H "Authorization: Bearer 12345abc" https://app.asana.com/api/1.0/users/me
>>
>> Returns 200/ok, and the right data.
>>
>> However, the pharo commands
>>
>> tmp1 := ZnClient new.
>> tmp1 headerAt: 'Authorization:' put: 'Bearer 12345abc'.
>> tmp1 url: 'https://app.asana.com/api/1.0/users/me'.
>> tmp1 get.
>>
>> Results in an authorisation error.
>>
>> I haven't tried using Zinc to access authenticated sites before, what am I doing wrong?
>>
>> Cheers
>> Andy


Reply | Threaded
Open this post in threaded view
|

Re: Adding an Authorization Bearer header via Zinc

Andy Burnett
In reply to this post by Andy Burnett
Norbert said

<<<
You have a colon in the name of the header. I?m not sure zinc removes it. It could be a problem.

>>>

Ah, spot on. Apparently, we need the colon for Curl, but not for Pharo.  Also, response setAuthorization turned out to be the best approach. For anyone searching this list, in the future,  for Asana connectivity, my PoC is:

tmp1 := ZnClient new.
tmp1 request setAuthorization: 'Bearer <put your personal access token here>'; 
tmpJSON := NeoJSONReader fromString: tmp1 get.