Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get the Authorization to work. #11

Closed
fearlex opened this issue Oct 8, 2015 · 2 comments
Closed

Can't get the Authorization to work. #11

fearlex opened this issue Oct 8, 2015 · 2 comments
Labels

Comments

@fearlex
Copy link

fearlex commented Oct 8, 2015

I love the idea behind slim-jwt-auth and i'm trying to use it for my API, but i'm completely stuck trying to get my supersecret key to even validate.

Somehow it is not clear to me, how to properly pass the secret key to the Middleware for it to properly authenticate it, and respond.

I already added the configuration needed to the .htaccess.

Maybe i'm doing something wrong ? Do i need to encode the secret pass first at http://jwt.io/ ??

I have spent hours trying to understand how to properly validate this and nothing, if you can kindly point me in the right direction, i will most likely appreciate it, as it is not clear in the docs.

Thank you so much !

@tuupola
Copy link
Owner

tuupola commented Oct 8, 2015

You pass the secret key for verifying signature in the secret parameter. You must use the same secret for signing the token when you generate it.

$app->add(new \Slim\Middleware\JwtAuthentication([
    "secret" => "supersecretkeyyoushouldnotcommittogithub"
]));

I do not know how you generated the token, but looking at the example url above the header it tries to send is.

Authorization: Bearer r8uGz9YQFPLdmWQBHRU9eNYe2j3FP4rLQ9NgrShQTBv7FMxjaXnjhJcvUkXeh7gS

The token part is not a valid JWT.

Header with valid example JWT token looks something like below. You can also verify this. Token is signed using secret fearlex (you need to write that in the verify box).

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQXJsZXlzIFJlc2NvIiwiYWRtaW4iOnRydWV9.Rvsr4CScemkXpY0qvA21iF1hD07yGiGZJSo9REoXYcE

To test Slim with the above token you must pass the correct secret of course.

$app->add(new \Slim\Middleware\JwtAuthentication([
    "secret" => "fearlex"
]));

Middleware itself expects to find the token in either the Authorization: Bearer header or cookie named token.

@fearlex
Copy link
Author

fearlex commented Oct 8, 2015

Thank you so much, your response help clarify a few things. I appreciate you taking your time to help and to build such an amazing tool.

Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants