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

Default headers not being attached to the requests #6

Closed
jantunes91 opened this issue May 12, 2017 · 5 comments
Closed

Default headers not being attached to the requests #6

jantunes91 opened this issue May 12, 2017 · 5 comments

Comments

@jantunes91
Copy link

Hi, I copied your exact same code and attached it to my project, but when I call the JwtHttp methods (put, get, post), the Authorization header doesn't seem to be attached to the request.

What can be the problem?

@leonardobazico
Copy link
Owner

You're setting the token on local storage or in other base?

After the login you need to record the token in some place

@mrtks13
Copy link

mrtks13 commented May 15, 2017

hi lenonardo,

I have same problem.Refresh token header doesnt attach to request.So I can not get refresh token at server side. Is this normal?

Request URL:http://localhost:8080/xx/refreshtoken/
Request Method:POST
Status Code:417
Remote Address:[::1]:8080
Referrer Policy:no-referrer-when-downgrade
Response Headers
(12)
Request Headers
view source
Accept:application/json
Accept-Encoding:gzip, deflate, br
Accept-Language:tr-TR,tr;q=0.8,en-US;q=0.6,en;q=0.4
Access-Control-Allow-Methods:GET,PUT,POST,HEAD,DELETE
Access-Control-Allow-Origin:*
Authorization:cosmo eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJldGhlbXN1bGFuIiwiY3JlYXRlZCI6MTQ5NDgyOTc1MzA2OCwic2Vzc2lvbklkIjoyMDksImV4cCI6MTQ5NDgyOTgxM30.jUpaiczLX-7dw3js0UWVGLd7uIGYUbz2jUYsgWYgdz3TZRMNbd86JwcduxjFquxK7pSh6aA3IaJnltMxxHvzhg
Connection:keep-alive
Content-Length:23
Content-Type:application/json
Cookie:JSESSIONID=95DAD36D5D84E407B1B28612B7AACB00; locale=tr-TR; currency=TRY
Host:localhost:8080
Origin:http://localhost:4200
Referer:http://localhost:4200/
screenResolutionHeight:925
screenResolutionWidth:908
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Request Payload
view source
{type: "refresh"}
type
:
"refresh"

}

module:
export function getJwtHttp(http: Http, options: RequestOptions) {
let url = ${environment.baseURL}${"refreshtoken/"};
let jwtOptions = {
endPoint: url,
// optional
payload: {type: 'refresh'},
beforeSeconds: 30, // refresh tokeSn before 10 min
tokenName: 'refresh_token',
headerPrefix: 'cosmo',
refreshTokenGetter: (() => localStorage.getItem('refresh_token')),
tokenSetter: ((res: Response): boolean | Promise => {
let token: JwtAuthenticationResponse = res.json();

  if (!token.token || !token.refresh_token) {
    localStorage.removeItem('id_token');
    localStorage.removeItem('refresh_token');

    return false;
  }

  localStorage.setItem('id_token', token.token);
  localStorage.setItem('refresh_token', token.refresh_token);

  return true;
})

};
console.log("jwtOptions" + jwtOptions);
let window = getWindowSize();
let authConfig = new AuthConfig({
tokenName: 'token',
headerName: 'Authorization',
headerPrefix: 'cosmo',
noJwtError: true,
noClientCheck: false,
tokenGetter: (() => localStorage.getItem('id_token')),
globalHeaders: [{'Content-Type': 'application/json'},
{'Accept': 'application/json'},
{'Access-Control-Allow-Origin': '*'},

  {
    'Access-Control-Allow-Methods': 'GET,PUT,POST,HEAD,DELETE',
    'Access-Control-Allow-Credentials': 'true',
    'Access-Control-Request-Headers': '*'
  }
],

});

authConfig.getConfig().globalHeaders.push({'screenResolutionWidth': window.width});
authConfig.getConfig().globalHeaders.push({'screenResolutionHeight': window.height});

let jwtHttp = new JwtHttp(
new JwtConfigService(jwtOptions, authConfig),
http,
options
);

console.log("jwtHttp module load" +JSON.stringify(jwtHttp) );
return jwtHttp;
}

@jantunes91
Copy link
Author

At login, I set both refresh token and id token at local storage

@jantunes91
Copy link
Author

I think it's fixed somehow. Don't know exactly what I did

@jantunes91
Copy link
Author

I have a problem now, that the endPoint defined in the options is called in every request. Is this normal behaviour?

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

No branches or pull requests

3 participants