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

Several issues with adal5-http.service #3

Closed
jo-me opened this issue Jan 9, 2018 · 11 comments
Closed

Several issues with adal5-http.service #3

jo-me opened this issue Jan 9, 2018 · 11 comments
Labels

Comments

@jo-me
Copy link

jo-me commented Jan 9, 2018

Hey there

I've integrated your adal wrapper and found several issues with the Adal5HTTPService.

  1. Contrary to this.http.request throws error in http service #1 the angular common http client's sendrequest has 3 arguments: method, url, options, see the debugger output here:
    image

If the method is omitted, then the request object becomes messed up. The URL is in the method field...
Not sure where the difference comes from, but I'm using Angular 5.1.

  1. The authorization header is not added if there are already headers present in the request.
    adal-angular4 does not have this issue.

Both issues can be fixed by replacing the block in sendRequest method with:

authenticatedCall = this.service.acquireToken(resource)
	.flatMap(function (token) {
		if (options.headers == null) {
			options.headers = new http_1.HttpHeaders();
		}
		options.headers = options.headers.append('Authorization', 'Bearer ' + token);
		return _this.http.request(method, url, options)
			.catch(_this.handleError);
	});
@grumar
Copy link
Owner

grumar commented Jan 18, 2018

Fixed in d021fed, please let me now if everything works like expected.

@geerzo
Copy link

geerzo commented Jan 21, 2018

This works for me. I would change
options.headers = options.headers.append('Authorization', 'Bearer ' + token);
to
options.headers = options.headers.set('Authorization', 'Bearer ' + token);

This will ensure that if someone set that field already it's overwritten. Otherwise you wind up with 2 Authorization headers.

@pandianramalingam
Copy link

Hi @grumar ,

Set authorization header code throwing error if there are already headers present in the request.

BR,
PR

@geerzo
Copy link

geerzo commented Jan 23, 2018

Yes, the existing code has an error, this change fixes it.

@pandianramalingam
Copy link

when we can expect updated version ?

@grumar
Copy link
Owner

grumar commented Jan 27, 2018

@geerzo @pandianramalingam
I made some changes in d021fed few days ago. Did You try lastest version?

@geerzo
Copy link

geerzo commented Jan 27, 2018

@grumar yes I have and it doesn’t work if the headers is already set because the local headers variable never gets set. You if block checks if options.headers is null then sets the headers variable but if that check fails the headers variable is never set but the next line sets the Authorization header and it fails because headers is null.

@jo-me
Copy link
Author

jo-me commented Jan 30, 2018

The original issue is resolved. THanks for that!

For more fault tolerance, I'd check if the options parameter is actually set because otherwise the request will fail altogether. If no special http options are needed the parameter could be omitted.

@stamler
Copy link

stamler commented Jan 30, 2018

@jo-me Making observe: optional in the options object and using the HttpObserve type (like HttpClient does) should solve the problem. I did it but haven't tested it yet. May be a nice update to @grumar 's code.

@grumar grumar added the bug label Mar 18, 2018
@grumar
Copy link
Owner

grumar commented Mar 20, 2018

Fixed in #22 & #23

@grumar
Copy link
Owner

grumar commented Mar 23, 2018

published as beta
npm install adal-angular5@2.1.1

@jo-me jo-me closed this as completed Aug 28, 2018
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

5 participants