0
votes

I have created two project in Laravel make one is Passport Server and another is Client. and I've configure full Passport in my Server project. and I'm get the access_token also.

When I Authorize my Client project it's show this in my browser.

{ "token_type": "Bearer", "expires_in": 31536000, "access_token":*******, "refresh_token":****** }

Now, my Question is how can i pass/grant access_token for an user and go to my client panel. I've already check using postman. now i want doing this from my browser.

1

1 Answers

0
votes

Try this code in your view page :

  let url = 'http://example.com/slug';
  $.ajax({
        url         : url,
        method      : "POST",
        dataType    : "json",
        crossDomain : true,
        contentType : "application/json; charset=utf-8",
        data        : JSON.stringify(data),
        cache       : false,
        beforeSend: function (xhr) {
              /* Authorization header */
              xhr.setRequestHeader("Authorization","Bearer "+accessToken);
        },
        success: function (data) {
              // do something
        },
        error: function (jqXHR, textStatus, errorThrown) {
              // do something
        }
  });