Skip to main content
added 106 characters in body
Source Link
Laiv
  • 14.8k
  • 2
  • 33
  • 71

Be consistent

Some may say this is unnecessary (and not too long ago I would have agreed) but these days, with so many auth protocols, if we use the Authorization header to pass an API key, it is worth informing the type too because API keys are not self-descriptive per se 1.

Why do I think it is worth it? Because nowadays supporting different authentication or/and authorization protocols havehas become a must-have. If we plan to use the Authorization header for all these protocols, we have to make our auth service consistent. The way to communicate what kind of token we send and what authorization protocol should be applied should go in the header too.

Authorization: Basic XXXX
Authorization: Digest XXXX
Authorization: Bearer XXXX
Authorization: ApiKey-v1 XXXX
Authorization: ApiKey-v2 XXXX

I used to don't care about this, but after working with mobile clients or sensors, whichin which updates were not guaranteed, I started to. I started to be more consistent in the way I implement security so that I can keep backwards compatibility. With the token's type informed I can invalidate requests from a specific set of clients (the outdated ones), add new schemes and differentiate old clients from new ones, and change auth validations for one or another scheme without causing breaking changes. I also can apply specific rules in the API Gateways based on the authorization scheme informed. For example, I can redirect old schemes to specific versions of my web APIs which are deployed apart from the main ones.

Concerns

The problems I faced implementing my own schemes hashave been similar to the one commented.

On the other hand, I found a consideration that a custom Authorization scheme can be unexpected and unsupported by some clients and leads to custom code anyway

Say clients, say libraries, frameworks, reverse proxies. A custom header can be rejected or ignored. In the worse of the cases, it can also collide.

Collisions can be problematic, but all other issues are likely to be solved by tackling configurations.

Advantages

One important advantage is cache. Shared caches won't cache the header (and that's good of course) unless you say otherwise.

So Authorization or custom header?

ToIn my experience, both take me almost the same work and time to implement, with a slight difference with having. I had more room for design when I have implemented custom headers. However, more room for design also meant more chances to overcomplicate things or reinvent the wheel.

Technically, there could be very little or no difference amongbetween the two, but I have found the consistency to be a property of any solution I value for what itgood feature. It provides me, with clearness and understanding. In my case, adding new schemes was reduced to addadding 2 new abstractions (implemented by the same concrete class): TokenHandler and TokenValidator. The handlerHandler only checks whether the request header AuthorizationAuthorization informs the supported scheme. The ValidatorValidator is anything I need to validate the token. Altogether working from a single request filter, instead of from a chain of filters or a big ball of mud.


1: I find this answer to be very clear regarding API Keys

Be consistent

Some may say this is unnecessary (and not too long ago I would have agreed) but these days, with so many auth protocols, if we use the Authorization header to pass an API key, worth informing the type too because API keys are not self-descriptive per se 1.

Why do I think it worth it? Because nowadays supporting different authentication or/and authorization protocols have become a must-have. If we plan to use the Authorization header for all these protocols, we have to make our auth service consistent. The way to communicate what kind of token we send and what authorization protocol should be applied should go in the header too.

Authorization: Basic XXXX
Authorization: Digest XXXX
Authorization: Bearer XXXX
Authorization: ApiKey-v1 XXXX
Authorization: ApiKey-v2 XXXX

I used to don't care about this, but after working with mobile clients or sensors, which updates were not guaranteed, I started to. I started to be more consistent in the way I implement security so that I can keep backwards compatibility. With the token's type informed I can invalidate requests from a specific set of clients (the outdated ones), add new schemes and differentiate old clients from new ones, change auth validations for one or another scheme without causing breaking changes. I also can apply specific rules in the API Gateways based on the authorization scheme informed. For example, I can redirect old schemes to specific versions of my web APIs which are deployed apart from the main ones.

Concerns

The problems I faced implementing my own schemes has been similar to the one commented.

On the other hand, I found a consideration that a custom Authorization scheme can be unexpected and unsupported by some clients and leads to custom code anyway

Say clients, say libraries, frameworks, reverse proxies. A custom header can be rejected or ignored. In the worse of the cases, it can also collide.

Advantages

One important advantage is cache. Shared caches won't cache the header (and that's good of course) unless you say otherwise.

So Authorization or custom header?

To my experience, both take me almost the same work and time to implement, with a slight difference with having more room for design when I have implemented custom headers. However, more room for design also meant more chances to overcomplicate things.

Technically there could be very little or no difference among the two, but I have found the consistency to be a property of any solution I value for what it provides me, clearness and understanding. In my case, adding new schemes was reduced to add 2 new abstractions (implemented by the same concrete class): TokenHandler and TokenValidator. The handler only checks whether the request header Authorization informs the supported scheme. The Validator is anything I need to validate the token. Altogether working from a single request filter, instead of from a chain of filters or a big ball of mud.


1: I find this answer to be very clear regarding API Keys

Be consistent

Some may say this is unnecessary (and not too long ago I would have agreed) but these days, with so many auth protocols, if we use the Authorization header to pass an API key, it is worth informing the type too because API keys are not self-descriptive per se 1.

Why do I think it is worth it? Because nowadays supporting different authentication or/and authorization protocols has become a must-have. If we plan to use the Authorization header for all these protocols, we have to make our auth service consistent. The way to communicate what kind of token we send and what authorization protocol should be applied should go in the header too.

Authorization: Basic XXXX
Authorization: Digest XXXX
Authorization: Bearer XXXX
Authorization: ApiKey-v1 XXXX
Authorization: ApiKey-v2 XXXX

I used to don't care about this, but after working with mobile clients or sensors, in which updates were not guaranteed, I started to. I started to be more consistent in the way I implement security so that I can keep backwards compatibility. With the token's type informed I can invalidate requests from a specific set of clients (the outdated ones), add new schemes and differentiate old clients from new ones and change auth validations for one or another scheme without causing breaking changes. I also can apply specific rules in the API Gateways based on the authorization scheme. For example, I can redirect old schemes to specific versions of my web APIs which are deployed apart from the main ones.

Concerns

The problems I faced implementing my own schemes have been similar to the one commented.

On the other hand, I found a consideration that a custom Authorization scheme can be unexpected and unsupported by some clients and leads to custom code anyway

Say clients, say libraries, frameworks, reverse proxies. A custom header can be rejected or ignored. In the worse of the cases, it can also collide.

Collisions can be problematic, but all other issues are likely to be solved by tackling configurations.

Advantages

One important advantage is cache. Shared caches won't cache the header (and that's good of course) unless you say otherwise.

So Authorization or custom header?

In my experience, both take me almost the same work and time to implement, with a slight difference. I had more room for design when I implemented custom headers. However, more room for design also meant more chances to overcomplicate things or reinvent the wheel.

Technically, there could be very little or no difference between the two, but I have found the consistency to be a good feature. It provides me with clearness and understanding. In my case, adding new schemes was reduced to adding 2 new abstractions (implemented by the same concrete class): TokenHandler and TokenValidator. The Handler only checks whether the request header Authorization informs the supported scheme. The Validator is anything I need to validate the token. Altogether working from a single request filter instead of a chain of filters or a big ball of mud.


1: I find this answer to be very clear regarding API Keys

added 804 characters in body
Source Link
Laiv
  • 14.8k
  • 2
  • 33
  • 71

If you use Authorization, beBe consistent

Some will argue that the followingmay say this is unnecessary (and not too long ago I would have agreed with them) but, these days, with so many auth protocols, if we use the Authorization header we should informto pass an API key, worth informing the type of the token,too because  API keys are not self-descriptive per se 1.

Why do I think it's necessary and why I do think it's importantit worth it? Because nowadays supporting different authentication or/authorizationand authorization protocols hashave become a must-have. If we plan to use the Authorization header for all these protocols, we have to make our auth service consistent. The way to communicate what kind of token we send and what authorization protocol should be applied should go in the header too.

Authorization: Basic xxxx
Authorization: Digest xxxx
Authorization: Bearer xxxx
Authorization: ApiKey-v1 xxxx
Authorization: ApiKey-v2 xxxx
Authorization: Basic XXXX
Authorization: Digest XXXX
Authorization: Bearer XXXX
Authorization: ApiKey-v1 XXXX
Authorization: ApiKey-v2 XXXX

I used to don't care about this, but after working with app client apps whosemobile clients or sensors, which updates were not guaranteed (mobiles and sensors mostly), I started to. I started to be more cautiousconsistent in the way I implement security so that I can expand it without messing withkeep backwards compatibility. With the token's type informed I can invalidate requests from a specific set of clients (the outdated ones), add new schemes and differentiate old clients from new ones, change auth validations for one or another scheme without too much paincausing breaking changes. I also can apply specific rules in the API Gateways based on the server sideauthorization scheme informed. For example, I can redirect old schemes to specific versions of my web APIs which are deployed apart from the main ones.

On the other hand, I found a consideration that a custom Authorization scheme can be unexpected and unsupported by some clients and leads to custom custom code anyway

Say clients, say libraries, frameworks, reverse proxies. A custom header can be rejected or ignored. In the worse of the cases, it can also collide.

To my experience, implementing my own Authorization scheme has takenboth take me almost the very same amount of work (or more) than implementing custom authorization headersand time to implement, with thea slight difference ofwith having more freedom ofroom for design and more control over the cache when I have usedimplemented custom headers. The reason is rather stupidHowever, most ofmore room for design also meant more chances to overcomplicate things.

Technically there could be very little or no difference among the timetwo, but I have found the Cache-control setconsistency to no-cache or no-store, allowingbe a property of any solution I value for what it provides me to make the calls, clearness and understanding. In my case, adding new schemes was reduced to the server more deterministicadd 2 new abstractions (thisimplemented by the same concrete class): TokenHandler and TokenValidator. The handler only checks whether the request header Authorization informs the supported scheme. The Validator is important when it comesanything I need to tracking and testing) regardlessvalidate the topologytoken. Altogether working from a single request filter, instead of the networkfrom a chain of filters or a big ball of mud.

If you use Authorization, be consistent

Some will argue that the following is unnecessary (and not too long ago I would have agreed with them) but, these days, if we use the Authorization header we should inform the type of the token, because  API keys are not self-descriptive per se 1.

Why do I think it's necessary and why I do think it's important? Because nowadays supporting different authentication/authorization protocols has become a must-have. If we plan to use the Authorization header for all these protocols, we have to make our auth service consistent. The way to communicate what kind of token we send and what authorization protocol should be applied should go in the header too.

Authorization: Basic xxxx
Authorization: Digest xxxx
Authorization: Bearer xxxx
Authorization: ApiKey-v1 xxxx
Authorization: ApiKey-v2 xxxx

I used to don't care about this, but after working with app client apps whose updates were not guaranteed (mobiles and sensors mostly), I started to. I started to be more cautious in the way I implement security so that I can expand it without messing with clients and without too much pain on the server side.

On the other hand, I found a consideration that a custom Authorization scheme can be unexpected and unsupported by some clients and leads to custom code anyway

Say clients, say libraries, frameworks, reverse proxies.

To my experience, implementing my own Authorization scheme has taken me the very same amount of work (or more) than implementing custom authorization headers, with the slight difference of having more freedom of design and more control over the cache when I have used custom headers. The reason is rather stupid, most of the time I have the Cache-control set to no-cache or no-store, allowing me to make the calls to the server more deterministic (this is important when it comes to tracking and testing) regardless the topology of the network.

Be consistent

Some may say this is unnecessary (and not too long ago I would have agreed) but these days, with so many auth protocols, if we use the Authorization header to pass an API key, worth informing the type too because API keys are not self-descriptive per se 1.

Why do I think it worth it? Because nowadays supporting different authentication or/and authorization protocols have become a must-have. If we plan to use the Authorization header for all these protocols, we have to make our auth service consistent. The way to communicate what kind of token we send and what authorization protocol should be applied should go in the header too.

Authorization: Basic XXXX
Authorization: Digest XXXX
Authorization: Bearer XXXX
Authorization: ApiKey-v1 XXXX
Authorization: ApiKey-v2 XXXX

I used to don't care about this, but after working with mobile clients or sensors, which updates were not guaranteed, I started to. I started to be more consistent in the way I implement security so that I can keep backwards compatibility. With the token's type informed I can invalidate requests from a specific set of clients (the outdated ones), add new schemes and differentiate old clients from new ones, change auth validations for one or another scheme without causing breaking changes. I also can apply specific rules in the API Gateways based on the authorization scheme informed. For example, I can redirect old schemes to specific versions of my web APIs which are deployed apart from the main ones.

On the other hand, I found a consideration that a custom Authorization scheme can be unexpected and unsupported by some clients and leads to custom code anyway

Say clients, say libraries, frameworks, reverse proxies. A custom header can be rejected or ignored. In the worse of the cases, it can also collide.

To my experience, both take me almost the same work and time to implement, with a slight difference with having more room for design when I have implemented custom headers. However, more room for design also meant more chances to overcomplicate things.

Technically there could be very little or no difference among the two, but I have found the consistency to be a property of any solution I value for what it provides me, clearness and understanding. In my case, adding new schemes was reduced to add 2 new abstractions (implemented by the same concrete class): TokenHandler and TokenValidator. The handler only checks whether the request header Authorization informs the supported scheme. The Validator is anything I need to validate the token. Altogether working from a single request filter, instead of from a chain of filters or a big ball of mud.

added 1338 characters in body
Source Link
Laiv
  • 14.8k
  • 2
  • 33
  • 71

If you use Authorization, be consistent

Some will argue that the following is unnecessary (and not too long ago I would have agreed with them) but, these days, if we use the Authorization header we should inform the type of the token, because API keys don't belong to any specific authentication or authorization protocolare not self-descriptive per se 1. We could

Why do I think it's necessary and why I do think it's important? Because nowadays supporting different authentication/authorization protocols has become a must-have. If we plan to use the Authorization header but, as you commentedfor all these protocols, it would take uswe have to implementmake our own schemeauth service consistent. The way to communicate what kind of token we send and what authorization protocol. Usually reinventing the wheel should be applied should go in security is a bad idea, so it's good to leave Authorizationthe header for well-known authorization standards.2too.

Authorization: Basic xxxx
Authorization: Digest xxxx
Authorization: Bearer xxxx
Authorization: ApiKey-v1 xxxx
Authorization: ApiKey-v2 xxxx

When I have implemented API Keys authorizationsused to don't care about this, but after working with app client apps whose updates were not guaranteed (mobiles and sensors mostly), I wantedstarted to state clearly that. I started to be more cautious in the authenticationway I implement security so that I can expand it without messing with clients and without too much pain on the authorization protocols were specific ofserver side.

Concerns

The problems I faced implementing my domain and they didn't respondown schemes has been similar to any known protocolthe one commented.

On the other hand, I found a consideration that a custom Authorization scheme can be unexpected and unsupported by some clients and leads to custom code anyway

Say clients, hencesay libraries, frameworks, reverse proxies.

Advantages

One important advantage is cache. Shared caches won't cache the custom header (and that's good of course) unless you say otherwise. Anyways

So Authorization or custom header?

To my experience, it'simplementing my own convention that probably only make sense toAuthorization scheme has taken me the very same amount of work (or more) than implementing custom authorization headers, with the slight difference of having more freedom of design and more control over the cache when I have used custom headers.

Worth to mention that some The reason is rather stupid, most of the largest API providers ontime I have the market still support API key authorizations and some allow usCache-control set to send no-cache or no-store, allowing me to make the calls to the server more deterministic key in the URL(this is important when it comes to tracking and testing) regardless the topology of the network.


1: I find this answer to be very clear regarding API Keys

2: However, you will find many articles and opinions (some of them very well argued) in favour of the Authorization header.

API keys don't belong to any specific authentication or authorization protocol1. We could use Authorization header but, as you commented, it would take us to implement our own scheme and protocol. Usually reinventing the wheel in security is a bad idea, so it's good to leave Authorization header for well-known authorization standards.2.

When I have implemented API Keys authorizations, I wanted to state clearly that the authentication and the authorization protocols were specific of my domain and they didn't respond to any known protocol, hence the custom header. Anyways, it's my own convention that probably only make sense to me.

Worth to mention that some of the largest API providers on the market still support API key authorizations and some allow us to send the key in the URL.


1: I find this answer to be very clear regarding API Keys

2: However, you will find many articles and opinions (some of them very well argued) in favour of the Authorization header.

If you use Authorization, be consistent

Some will argue that the following is unnecessary (and not too long ago I would have agreed with them) but, these days, if we use the Authorization header we should inform the type of the token, because API keys are not self-descriptive per se 1.

Why do I think it's necessary and why I do think it's important? Because nowadays supporting different authentication/authorization protocols has become a must-have. If we plan to use the Authorization header for all these protocols, we have to make our auth service consistent. The way to communicate what kind of token we send and what authorization protocol should be applied should go in the header too.

Authorization: Basic xxxx
Authorization: Digest xxxx
Authorization: Bearer xxxx
Authorization: ApiKey-v1 xxxx
Authorization: ApiKey-v2 xxxx

I used to don't care about this, but after working with app client apps whose updates were not guaranteed (mobiles and sensors mostly), I started to. I started to be more cautious in the way I implement security so that I can expand it without messing with clients and without too much pain on the server side.

Concerns

The problems I faced implementing my own schemes has been similar to the one commented.

On the other hand, I found a consideration that a custom Authorization scheme can be unexpected and unsupported by some clients and leads to custom code anyway

Say clients, say libraries, frameworks, reverse proxies.

Advantages

One important advantage is cache. Shared caches won't cache the header (and that's good of course) unless you say otherwise.

So Authorization or custom header?

To my experience, implementing my own Authorization scheme has taken me the very same amount of work (or more) than implementing custom authorization headers, with the slight difference of having more freedom of design and more control over the cache when I have used custom headers. The reason is rather stupid, most of the time I have the Cache-control set to no-cache or no-store, allowing me to make the calls to the server more deterministic (this is important when it comes to tracking and testing) regardless the topology of the network.


1: I find this answer to be very clear regarding API Keys

deleted 1 character in body
Source Link
Laiv
  • 14.8k
  • 2
  • 33
  • 71
Loading
deleted 21 characters in body
Source Link
Laiv
  • 14.8k
  • 2
  • 33
  • 71
Loading
added 1 character in body
Source Link
Laiv
  • 14.8k
  • 2
  • 33
  • 71
Loading
deleted 110 characters in body
Source Link
Laiv
  • 14.8k
  • 2
  • 33
  • 71
Loading
spellcheck revision
Source Link
Laiv
  • 14.8k
  • 2
  • 33
  • 71
Loading
Source Link
Laiv
  • 14.8k
  • 2
  • 33
  • 71
Loading