JWT auth in lumen - laravel-5

I complete Login With Token Generate Like This
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vbG9jYWxob3N0L2x1bWVuL2F1dGgvbG9naW4iLCJpYXQiOjE0NzUwNjAwMzMsImV4cCI6MTQ3NTA2MzYzMywibmJmIjoxNDc1MDYwMDMzLCJqdGkiOiIwOTFjYWNhZGRlODQ1NjNhMzc4M2JkM2EwNDdkZmM3YSIsInN1YiI6M30.VjXTSkzrmzTQSTZvp3VxlWacL8VHyM8XBUa5db8GOOI"
But When i Run api with jwt.auth middleware it give response
{
"message": "Token not provided"
}
How I can solve it

Are you sure you are providing the token in the headers properly as specified in the JWT documentation?
You need to send the Authorization header followed by Bearer TOKEN.
So the final result in your case would be:
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vbG9jYWxob3N0L2x1bWVuL2F1dGgvbG9naW4iLCJpYXQiOjE0NzUwNjAwMzMsImV4cCI6MTQ3NTA2MzYzMywibmJmIjoxNDc1MDYwMDMzLCJqdGkiOiIwOTFjYWNhZGRlODQ1NjNhMzc4M2JkM2EwNDdkZmM3YSIsInN1YiI6M30.VjXTSkzrmzTQSTZvp3VxlWacL8VHyM8XBUa5db8GOOI

Related

Laravel using basic.auth access_token

i am follow laravel documentation about Basic Authentication
i already create an API who response
"token_type": "Bearer",
"expires_in": 31536000,
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9"
and i use the access_token on postman as
Header
Authentication : Bearer {{access_token}}
and set my route with Route()->middlewire(auth.basic)
the response always
{
"message": "Invalid credentials.",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\UnauthorizedHttpException",
...
What I do wrong?
I figure it out
i did not read the right documentation
I read basic auth documentation on laravel but actually I use basic auth with passport and on passport the middleware is not auth.basic but client, now i can use the return access_token

Set and check token 'Bearer xxxxx' in body instead header

I'm using Laravel and use Tymon\JWTAuth for authentication.
As we know, when user login successfully, we will set the token to the header and when user call other api, Laravel will check it in header: "Authorization: Bearer xxxxx" by default
My spec is: in body I will pass the token with param: "token: Bearer xxxx", so I wonder if I could check the token in body and how to do this. It is my current spec and could not be changed to move to header, please help me
You can create a middleware to check the Authorization property inside your request body, see the docs here. Inside that middleware, you can check whether the token sent is valid or not.

Getting Weird Invalid Token Error Message At Postman

I'm trying to connect to an API of a website using Token Authorization in Postman.
So the URL that I'm trying to connect is a GET URL that goes like this:
https://seller.digikala.com/api/v1/profile/
And then at Postman, I set the Authorization type to BearerToken and copied and pasted the token.
And Headers is also set to Content-Type of application/json:
But I don't know why I get this error:
{
"status": 401,
"message": "Invalid token!"
}
I also test the token at the jwt.io website and it says: Invalid Signature!
So the question is, does the website provide me a wrong and invalid token (because I just copy and paste it and no chance of entering an incorrect token)?
What are the other ways for authorizing this token and how can I get the proper response?
BearerToken is not always JWT
BearerToken is a type of Authorization Header, you can pass to an http endpoint.
BearerTokens can have multiple token_type, like:
jwt,
api_token,
...
the BearerToken is not always jwt, it can have multiple algorithm.
the 12|xxx format is like api_token
Note: one of the signs if you want to know the token is jwt, if its
format is url encoded string with 2 dots, (xxx.yyy.zzz) its a chance
that it would be JWT token
Validating JWT
in the jwt.io you should provide the digikala.com public key to validate the signature.
It said invalid token, because you haven't provide, digikala
public key
but as decoder showed up, the token you have provided is a jwt token with payload data of :
{
"token_id" : 970,
"payload" : null
}
TD;DR
I guess you can access if you login again and try new token

send api_token through header instead of query parameter

I am trying to build APIS in laravel 5.6, and for api authentication I am using laravel basic API token authentication.
For get request or post request, I need to pass api_token in the query parameter. Is there any way where I can pass the api_token in the header instead of url string?
I followed Laravel - Send api_token within the header .
For GET endpoint, my api url is like this
http://localhost:8000/api/category-list?api_token=YDYsOgkSIOWDdE1NG3Ih1yCkciatOPvtpF1gXTmy8GL1r72mcDEgNDkkZ5jh&Accept=application%2Fjson
For POST my parameter are like this
As you can see, for get I need to add the api token in the url, and for POST I need to add in the body.
If I add the api token in the header, it says unauthorized access.
Header setting where authorization does not work
When you send api token through header the name of the header should be Authorization not api_token.
Also prepend the type of token Bearer to authorization header.
So finally the header should look like:
Authorization: Bearer aEzKClugYHJQsr6If48i1y24KneTT7YwMtNrri7JNhGyEIbJv6YP5SrsFXx2

Spring Security: How to pass oauth2 access token in request headers

On successful login to my spring security application configured with Oauth2, I received a response with Oauth2 token.
For the subsequent request I passed Oauth2 access_token in URI Query Parameter like this
http://localhost:8090/myapplication/users/user?access_token=4c520795-eb07-4c2d-a91b-474c85fb481e
It is working fine.
But instead of passing token in URI to make it more secure I wanted to send token in request headers.How to do this?
Use the usual HTTP Authorization header:
Authorization: Bearer <your-token-here>
For example
Authorization: Bearer 4c520795-eb07-4c2d-a91b-474c85fb481e

Resources