0

followed by the access documentation

both are not working by using

  1. Authorization Header

  2. Query Parameter

Using the latest version of loopback 2.1.X.

I turned off the email verification and successfully got the AccessToken object from the initial login. The header and the query request are not working now.

ACCESS_TOKEN=6Nb2ti5QEXIoDBS5FQGWIz4poRFiBCMMYJbYXSGHWuulOuy0GTEuGx2VCEVvbpBK

Authorization Header

curl -X GET -H "Authorization: $ACCESS_TOKEN" \ http://localhost:3000/api/widgets

Query Parameter

curl -X GET http://localhost:3000/api/widgets?access_token=$ACCESS_TOKEN

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

2 Answers2

0

In header pass key as authorization not ACCESS_TOKEN

In query params pass key as accessToken not access_token

0

Here is what works for me in Angular 2 :

initRequestOptions(accessToken:any) {

        let headers = new Headers();
        headers.append('Content-Type', 'application/json');
        headers.append('Access-Control-Allow-Origin', '*');
        headers.append('Authorization', accessToken);
        return new RequestOptions({headers: headers});
    }

makeRequest(accessToken:any){
let options = this.initRequestOptions(accessToken);
this.http.get('http://' + apiUrl + '/api/MyModel, options)
            .subscribe(
               //...
            )
}

So basically you need to create a headers object , add an 'Authorization' item whoes value is the access token , and use the headers object to create a RequestOptions object to be inserted in the request.

Also loopback explorer passes the access token as a url encoded parameter so this should work too :

http://localhost:3000/api/MyModel?access_token=X3Ovz4G1PfmPiNGgU5YgORPwPGLaVt9r8kU7f4tu1bDMyA4zbqiUEgeDAC3qkZLR
SifouTifou
  • 161
  • 1
  • 6