0
I’m using the Laravel 5.3 along with the JWT, but when I send the authentication by header it returns to me that I am not authenticated and I forward the token by parameter it displays me the result, follows my . htaccess
RedirectMatch 404 /\.git
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
Here’s the service that was created to add Bearer to all Apis requests,
function authService($q, $location) {
return {
getToken : getToken,
setToken : function (token) {
localStorage.setItem('token', token);
},
request : function (config) {
var url = config.url;
if (url.indexOf('../../../../api/') > -1) {
config.headers['Authorization'] = 'Bearer ' + getToken();
}
return config;
},
responseError: function (rejection) {
if(rejection.status === 401){
$location.path('/login');
}
return $q.reject(rejection);
}
};
function getToken() {
return localStorage.getItem('token');
}
}
Has anyone been through this case before? if I try to access all Apis by localhost works more on the web it keeps saying that it is not authenticated but if step www.example.com.br? token={token} it works
Are you using some package?
– novic
I am using this https://github.com/tymondesigns/jwt-authpackage, tin works normally on localhost, but not on the web.
– Jean Sumara
in the browser console is not showing any error, you have already noted this (press F12 and check on console and network tab if you have any error)?
– novic
if I send via get http://teste.com.br/api/usuario with Authorization no header it appears { "error":"Unauthenticated." } now if I send http://teste.com.br/api/usuario?token={token} it works normally
– Jean Sumara
Jean your angular code may be wrong! and so it should not be sending the header correctly, so I asked you to look with F12 on the console if it sends, I’m already thinking that not... I’ll take a look at an app I did and tell you.
– novic
All right then, I’ll wait and thank you very much!
– Jean Sumara
For his last comment it seems that is sent the
authorization
really weird.– novic
In my code I have a
factory
which is called$authorization
, on the line to put the Authorization and send would:$http.defaults.headers.common["Authorization"] = $authorization.token();
inside$authorization.token()
isreturn "bearer " + $cookies.get("Authorization");
I keep it in acookie
works perfectly.– novic
Exactly, mine is the same but it doesn’t work only if I forward the token by parameter, it seems that apache is not recognizing the request header
– Jean Sumara