Passport - "Unauthenticated." - Laravel 5.3

what is a passport card
passport prices
passport application form
passport acceptance facility
passport renewal post office
passport renewal near me
passport book vs card
where can i get a passport

I hope someone could explain why I'm unauthenticated when already has performed a successfull Oauth 2 authentication process.

I've set up the Passport package like in Laravel's documentation and I successfully get authenticated, receives a token value and so on. But, when I try to do a get request on, let say, /api/user, I get a Unauthenticated error as a response. I use the token value as a header with key name Authorization, just as described in the docs.

Route::get('/user', function (Request $request) {
    return $request->user();
})->middleware("auth:api");

This function is suppose to give back my self as the authenticated user, but I'm only getting Unauthenticated. Likewise, if I just return the first user, I'm again getting Unauthenticated.

Route::get('/test', function(Request $request) {
    return App\User::whereId(1)->first();
})->middleware("auth:api");

In a tutorial from Laracast, guiding through the setup of Passport, the guider doesn't have the ->middleware("auth:api") in his routes. But if its not there, well then there's no need for authentication at all!

Please, any suggestions or answers are more then welcome!


You have to set an expiration date for the tokens you are generating,

set the boot method in your AuthServiceProvider to something like the code below and try generating a new token. Passports default expiration returns a negative number

public function boot()
{
  $this->registerPolicies();
   Passport::routes();
   Passport::tokensExpireIn(Carbon::now()->addDays(15));
   Passport::refreshTokensExpireIn(Carbon::now()->addDays(30));
}

Renew my U.S. passport, After the 10-year passport has been expired for 5 years, you cannot renew it and you must apply in person using Form DS-11 if you want a new passport. You  Voted #1 By The Wall Street Journal. As a Registered Passport Courier We Expedite Your U.S. Passport Application in a Hurry.


Check your user model and the database table, if you have modified the primary id field name to say something other than "id" or even "user_id" you MIGHT run into issues. I debugged an issue regarding modifying the primary id field in my user model and database table to say "acct_id" instead of keeping it as just "id" and the result was "Unauthenticated" When I tried to get the user object via GET /user through the auth:api middleware. Keep in mind I had tried every other fix under the sun until I decided to debug it myself.

ALSO Be sure to UPDATE your passport. As it has had some changes made to it in recent weeks.

I'll link my reference below, it's VERY detailed and well defined as to what I did and how I got to the solution.

Enjoy!

https://github.com/laravel/passport/issues/151

Passport Application & Passport Renewal, Passports. Thousands of Post Offices™ around the U.S. accept first-time passport applications for the United States Department of State. Post Offices  Order 2"x2" Matte Finish Passport Photos in Minutes. Free Shipping, Same Day Pickup, and 1-Hour Pickup Available. Start Now!


I had this error because of that I deleted passport mysql tables(php artisan migrate:fresh), php artisan passport:install helps me. Remember that after removing tables, you need to re-install passport!

How Much Does It Cost to Get a Passport?, book: $110 application fee and a $35 execution fee. The new total fee is $145. Build Your Exact Passport and Know The Real Price Before You Buy or Lease. See What Others Paid and Feel Confident About The Price You Pay.


I had exactly the same error because I forgot to put http before the project name.

use Illuminate\Http\Request;

Route::get('/', function () {
    $query = http_build_query([
        'client_id' => 3,
        'redirect_uri' => 'http://consumer.dev/callback',
        'response_type' => 'code',
        'scope' => '',
    ]);

    // The redirect URL should start with http://
    return redirect('passport.dev/oauth/authorize?'.$query);
});

Route::get('/callback', function (Request $request) {
    $http = new GuzzleHttp\Client;

    $response = $http->post('http://passport.dev/oauth/token', [
        'form_params' => [
            'grant_type' => 'authorization_code',
            'client_id' => 3,
            'client_secret' => 'M8y4u77AFmHyYp4clJrYTWdkbua1ftPEUbciW8aq',
            'redirect_uri' => 'http://consumer.dev/callback',
            'code' => $request->code,
        ],
    ]);

    return json_decode((string) $response->getBody(), true);
});

Standard Passport Processing Still Available During Coronavirus , , please contact the facility directly to confirm the status of its operations. The British Nationality experts. Try Our Free Eligibility Assessment


How to Apply - Travel.gov, receive a faster processing time. There is a $60 fee for expedited requests. Start today by applying for or renewing your passport. I need a passport. #N#Apply in person. Children under age 16. Children age 16 and 17. Track my application status. What is a passport card? I already have a passport. #N#Renew my passport. Report it lost or stolen. Change or correct my passport. Track my renewal application status.


USPS Offers Passport Application Tips, How to apply, renew, or quickly get a passport. Also, learn how to get a passport for a child, check the status of your application, and how much it costs to get a  A passport card is more convenient and less expensive than a passport book, but it cannot be used for international travel by air. How to Apply for a U.S. Passport The application process is the same for either the passport book or card, even if you want both at the same time.


Getting or Renewing a U.S. Passport, The Department of Homeland Security provides information on the passport application process, obtaining a visa, border crossing documents,  The passport agent in Fairfax County would be able give you the passport form and witness your signature to obtain a passport. Passport acceptance agents at the Fairfax Offices require an appointment so you will have to call the postal office for an appointment.