Passport: Passport authentication is not working in laravel 5.3

Created on 25 Oct 2016  Â·  9Comments  Â·  Source: laravel/passport

I have set-up Laravel using passport as per the documentation here:

https://laravel.com/docs/5.3/passport.

I have written one route in API route and send request http://localhost/laravel_project/public/api/user using postman but its showing me below error:

NotFoundHttpException in RouteCollection.php line 161:
I have the following route (in routes/api.php):

Route::get('/user', function (Request $request) {
return array(
1 => "John",
2 => "Mary",
3 => "Steven"
);
})->middleware('auth:api');
but when I removed ->middleware('auth:api') line in the route it's working fine for me.

How can I fix this?

All 9 comments

try api/user

Items in the api.php get api on the front of the route.

@huntsfromshadow can you tell me how I can generate client_id and client_secret in the passport auth without Vue component?

Details are in https://laravel.com/docs/5.3/passport

Here though is the answer you are looking for.

If you arlready have a key you can use the JSON API.

Or if you need a starting client.

php artisan passport:client

Please answer of the below question in the stackoverflow link:

http://stackoverflow.com/questions/40284663/isuue-in-generating-oauth-client-and-requesting-access-token-via-code-in-laravel

Thanks

Sincerely,

Abdul Ovais Khan / ​PHP​ Developer
+971 504792715 ​
/ [email protected]
Skype: ovais.khan11 / LinkedIn
https://pk.linkedin.com/in/abdul-ovais-khan-b9280850

On Thu, Oct 27, 2016 at 12:19 AM, huntsfromshadow [email protected]
wrote:

try api/user

Items in the api.php get api on the front of the route.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/laravel/passport/issues/157#issuecomment-256465019,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ANqeUfW3uH7jj_vss9AYadrDRkbIhQBjks5q37XsgaJpZM4Kf6-G
.

I just want to ask you that how I can generate client id and secret via
coding? I don't want to use php artisan passport:client
command. Can you give me any example that how I can authenticate user if he
is accessing my API?

Waiting for your positive response.

Thanks

Sincerely,

Abdul Ovais Khan / ​PHP​ Developer
+971 504792715 ​
/ [email protected]
Skype: ovais.khan11 / LinkedIn
https://pk.linkedin.com/in/abdul-ovais-khan-b9280850

On Thu, Oct 27, 2016 at 4:54 PM, huntsfromshadow [email protected]
wrote:

Details are in https://laravel.com/docs/5.3/passport http://url

Here though is the answer you are looking for.

If you arlready have a key you can use the JSON API.

Or if you need a starting client.

php artisan passport:client

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/laravel/passport/issues/157#issuecomment-256632486,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ANqeUW5pceNJ4qUTG1_MkiBeRQI-TCzzks5q4J75gaJpZM4Kf6-G
.

@ovaiskhan11

Take a look at the vue files. Even if you don't use them they show you how to acomplish it.
https://github.com/laravel/passport/blob/1.0/resources/assets/js/components/Clients.vue

In general thorugh you'll send commands to /oauth/clients
as detaild in https://laravel.com/docs/5.3/passport#managing-clients

Just a tip: If your application won't work as a restful resource, you could use the CreateFreshApiMiddleware which will save the token on a cookie and will embbed it on the request. But, it will only work if, for example, you vue file make a get request to your backend, both running on laravel.

@huntsfromshadow, I am trying to do same things to generate client_id and
client_secret which you have mentioned in the link but didn't get the
result. Please check the below link:

http://stackoverflow.com/questions/40284663/issue-in-generating-oauth-client-and-requesting-access-token-via-code-in-laravel

Sincerely,

Abdul Ovais Khan / ​PHP​ Developer
+971 504792715 ​
/ [email protected]
Skype: ovais.khan11 / LinkedIn
https://pk.linkedin.com/in/abdul-ovais-khan-b9280850

On Thu, Oct 27, 2016 at 11:38 PM, huntsfromshadow [email protected]
wrote:

@ovaiskhan11 https://github.com/ovaiskhan11

Take a look at the vue files. Even if you don't use them they show you how
to acomplish it.
https://github.com/laravel/passport/blob/1.0/resources/
assets/js/components/Clients.vue http://url

In general thorugh you'll send commands to /oauth/clients
as detaild in https://laravel.com/docs/5.3/passport#managing-clients
http://url

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/laravel/passport/issues/157#issuecomment-256747296,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ANqeUeCRbhzNMpnRdvDitaSj6YE-UbZaks5q4P26gaJpZM4Kf6-G
.

@ovaiskhan11, why don't you just look at the gosh darn source code of the passport:client command???

It's clearly there:

// Programmatically create a passord grant client:
$clients->createPasswordGrantClient(
    null, $name, $redirectUrl
);

All you have to do in your parent class is use Laravel\Passport\ClientRepository;

Done, done, & done. Please check the source before gettin' all crazy on us. You can look at the src/Console/ClientCommand.php file on how to call the rest of the grant creation methods.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raksrivastava picture raksrivastava  Â·  3Comments

s4uron picture s4uron  Â·  3Comments

rudolfdobias picture rudolfdobias  Â·  3Comments

brryfrmnn picture brryfrmnn  Â·  3Comments

parth-vora-7 picture parth-vora-7  Â·  4Comments