Proper behaviour for publicly available api resource requested using expired authorization token
I know there are already many 401 vs 403 questions, but that's not my case.
What i'm asking is: what should a server ideally do if the requested api resource is publicly available (does not require authorization) but the request includes an authorization header with a token that is either incorrect or expired?
My reasoning is as follows: in theory server could ignore it and respond, but this feels like a very bad idea. For example business logic behind processing the request could differ depending on being authenticated or not. Client app should also get an instant feedback that it should reauthenticate, and not only if and when it hits a non-public end-point.
Being "badly authenticated" and therefore implicitly treated as an anonymous is a somewhat undefined and confusing behaviour i think.
So to sum up. Is it justified to use 400 in this particular case or is there any other, common practise?
rest api http-status-codes
add a comment |
I know there are already many 401 vs 403 questions, but that's not my case.
What i'm asking is: what should a server ideally do if the requested api resource is publicly available (does not require authorization) but the request includes an authorization header with a token that is either incorrect or expired?
My reasoning is as follows: in theory server could ignore it and respond, but this feels like a very bad idea. For example business logic behind processing the request could differ depending on being authenticated or not. Client app should also get an instant feedback that it should reauthenticate, and not only if and when it hits a non-public end-point.
Being "badly authenticated" and therefore implicitly treated as an anonymous is a somewhat undefined and confusing behaviour i think.
So to sum up. Is it justified to use 400 in this particular case or is there any other, common practise?
rest api http-status-codes
add a comment |
I know there are already many 401 vs 403 questions, but that's not my case.
What i'm asking is: what should a server ideally do if the requested api resource is publicly available (does not require authorization) but the request includes an authorization header with a token that is either incorrect or expired?
My reasoning is as follows: in theory server could ignore it and respond, but this feels like a very bad idea. For example business logic behind processing the request could differ depending on being authenticated or not. Client app should also get an instant feedback that it should reauthenticate, and not only if and when it hits a non-public end-point.
Being "badly authenticated" and therefore implicitly treated as an anonymous is a somewhat undefined and confusing behaviour i think.
So to sum up. Is it justified to use 400 in this particular case or is there any other, common practise?
rest api http-status-codes
I know there are already many 401 vs 403 questions, but that's not my case.
What i'm asking is: what should a server ideally do if the requested api resource is publicly available (does not require authorization) but the request includes an authorization header with a token that is either incorrect or expired?
My reasoning is as follows: in theory server could ignore it and respond, but this feels like a very bad idea. For example business logic behind processing the request could differ depending on being authenticated or not. Client app should also get an instant feedback that it should reauthenticate, and not only if and when it hits a non-public end-point.
Being "badly authenticated" and therefore implicitly treated as an anonymous is a somewhat undefined and confusing behaviour i think.
So to sum up. Is it justified to use 400 in this particular case or is there any other, common practise?
rest api http-status-codes
rest api http-status-codes
asked Nov 23 at 8:53
plunntic iam
591615
591615
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If this API itself is publicly available, and by publicly available you mean doesn't require any authentication to the user, why will you return to the user a response with Bad Request? Think to yourself if it makes sense, if its public, you can bypass any kind of validation and save some processing on the server.
Related with this:
"but this feels like a very bad idea. For example business logic behind processing the request could differ depending on being authenticated or not."
I think that in this case, you should change the API itself to require authentication, and not accept any kind of unauthorized user, or a user with an expired token.
Sorry if I didn't help much, but this is my opinion on this.
If its badly authenticated then it's not a public API, right?
A public API would respond in any scenario, could just have some restriction on requests by second.
I'd have to disagree. Let's say i have a CMS where both the front- and back-end are SPAs. Unless you have some specific requirement - which i don't have - it makes perfect sense to create one api serving both applications. And there you have it - some end-points require authorization, some don't, and some differ in behaviour depending on authorization. For example if you're authenticated as an admin you're getting some non-public data about posts, users which anonymous users shouldn't ever see.
– plunntic iam
Nov 24 at 5:46
Anyway, my point was, that a request with invalid authorization is indeed bad / broken. Client assumes - for example - his authenticated as an admin, but api can't respond the way client assumes because authorization is invalid at this point. But responding with only the public data may be (and probably is) something totaly different than what the client expects. That's why i think api should respond with 400 (or with other bad request type of code).
– plunntic iam
Nov 24 at 5:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443355%2fproper-behaviour-for-publicly-available-api-resource-requested-using-expired-aut%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If this API itself is publicly available, and by publicly available you mean doesn't require any authentication to the user, why will you return to the user a response with Bad Request? Think to yourself if it makes sense, if its public, you can bypass any kind of validation and save some processing on the server.
Related with this:
"but this feels like a very bad idea. For example business logic behind processing the request could differ depending on being authenticated or not."
I think that in this case, you should change the API itself to require authentication, and not accept any kind of unauthorized user, or a user with an expired token.
Sorry if I didn't help much, but this is my opinion on this.
If its badly authenticated then it's not a public API, right?
A public API would respond in any scenario, could just have some restriction on requests by second.
I'd have to disagree. Let's say i have a CMS where both the front- and back-end are SPAs. Unless you have some specific requirement - which i don't have - it makes perfect sense to create one api serving both applications. And there you have it - some end-points require authorization, some don't, and some differ in behaviour depending on authorization. For example if you're authenticated as an admin you're getting some non-public data about posts, users which anonymous users shouldn't ever see.
– plunntic iam
Nov 24 at 5:46
Anyway, my point was, that a request with invalid authorization is indeed bad / broken. Client assumes - for example - his authenticated as an admin, but api can't respond the way client assumes because authorization is invalid at this point. But responding with only the public data may be (and probably is) something totaly different than what the client expects. That's why i think api should respond with 400 (or with other bad request type of code).
– plunntic iam
Nov 24 at 5:53
add a comment |
If this API itself is publicly available, and by publicly available you mean doesn't require any authentication to the user, why will you return to the user a response with Bad Request? Think to yourself if it makes sense, if its public, you can bypass any kind of validation and save some processing on the server.
Related with this:
"but this feels like a very bad idea. For example business logic behind processing the request could differ depending on being authenticated or not."
I think that in this case, you should change the API itself to require authentication, and not accept any kind of unauthorized user, or a user with an expired token.
Sorry if I didn't help much, but this is my opinion on this.
If its badly authenticated then it's not a public API, right?
A public API would respond in any scenario, could just have some restriction on requests by second.
I'd have to disagree. Let's say i have a CMS where both the front- and back-end are SPAs. Unless you have some specific requirement - which i don't have - it makes perfect sense to create one api serving both applications. And there you have it - some end-points require authorization, some don't, and some differ in behaviour depending on authorization. For example if you're authenticated as an admin you're getting some non-public data about posts, users which anonymous users shouldn't ever see.
– plunntic iam
Nov 24 at 5:46
Anyway, my point was, that a request with invalid authorization is indeed bad / broken. Client assumes - for example - his authenticated as an admin, but api can't respond the way client assumes because authorization is invalid at this point. But responding with only the public data may be (and probably is) something totaly different than what the client expects. That's why i think api should respond with 400 (or with other bad request type of code).
– plunntic iam
Nov 24 at 5:53
add a comment |
If this API itself is publicly available, and by publicly available you mean doesn't require any authentication to the user, why will you return to the user a response with Bad Request? Think to yourself if it makes sense, if its public, you can bypass any kind of validation and save some processing on the server.
Related with this:
"but this feels like a very bad idea. For example business logic behind processing the request could differ depending on being authenticated or not."
I think that in this case, you should change the API itself to require authentication, and not accept any kind of unauthorized user, or a user with an expired token.
Sorry if I didn't help much, but this is my opinion on this.
If its badly authenticated then it's not a public API, right?
A public API would respond in any scenario, could just have some restriction on requests by second.
If this API itself is publicly available, and by publicly available you mean doesn't require any authentication to the user, why will you return to the user a response with Bad Request? Think to yourself if it makes sense, if its public, you can bypass any kind of validation and save some processing on the server.
Related with this:
"but this feels like a very bad idea. For example business logic behind processing the request could differ depending on being authenticated or not."
I think that in this case, you should change the API itself to require authentication, and not accept any kind of unauthorized user, or a user with an expired token.
Sorry if I didn't help much, but this is my opinion on this.
If its badly authenticated then it's not a public API, right?
A public API would respond in any scenario, could just have some restriction on requests by second.
answered Nov 23 at 9:01
TiagoM
1,48542560
1,48542560
I'd have to disagree. Let's say i have a CMS where both the front- and back-end are SPAs. Unless you have some specific requirement - which i don't have - it makes perfect sense to create one api serving both applications. And there you have it - some end-points require authorization, some don't, and some differ in behaviour depending on authorization. For example if you're authenticated as an admin you're getting some non-public data about posts, users which anonymous users shouldn't ever see.
– plunntic iam
Nov 24 at 5:46
Anyway, my point was, that a request with invalid authorization is indeed bad / broken. Client assumes - for example - his authenticated as an admin, but api can't respond the way client assumes because authorization is invalid at this point. But responding with only the public data may be (and probably is) something totaly different than what the client expects. That's why i think api should respond with 400 (or with other bad request type of code).
– plunntic iam
Nov 24 at 5:53
add a comment |
I'd have to disagree. Let's say i have a CMS where both the front- and back-end are SPAs. Unless you have some specific requirement - which i don't have - it makes perfect sense to create one api serving both applications. And there you have it - some end-points require authorization, some don't, and some differ in behaviour depending on authorization. For example if you're authenticated as an admin you're getting some non-public data about posts, users which anonymous users shouldn't ever see.
– plunntic iam
Nov 24 at 5:46
Anyway, my point was, that a request with invalid authorization is indeed bad / broken. Client assumes - for example - his authenticated as an admin, but api can't respond the way client assumes because authorization is invalid at this point. But responding with only the public data may be (and probably is) something totaly different than what the client expects. That's why i think api should respond with 400 (or with other bad request type of code).
– plunntic iam
Nov 24 at 5:53
I'd have to disagree. Let's say i have a CMS where both the front- and back-end are SPAs. Unless you have some specific requirement - which i don't have - it makes perfect sense to create one api serving both applications. And there you have it - some end-points require authorization, some don't, and some differ in behaviour depending on authorization. For example if you're authenticated as an admin you're getting some non-public data about posts, users which anonymous users shouldn't ever see.
– plunntic iam
Nov 24 at 5:46
I'd have to disagree. Let's say i have a CMS where both the front- and back-end are SPAs. Unless you have some specific requirement - which i don't have - it makes perfect sense to create one api serving both applications. And there you have it - some end-points require authorization, some don't, and some differ in behaviour depending on authorization. For example if you're authenticated as an admin you're getting some non-public data about posts, users which anonymous users shouldn't ever see.
– plunntic iam
Nov 24 at 5:46
Anyway, my point was, that a request with invalid authorization is indeed bad / broken. Client assumes - for example - his authenticated as an admin, but api can't respond the way client assumes because authorization is invalid at this point. But responding with only the public data may be (and probably is) something totaly different than what the client expects. That's why i think api should respond with 400 (or with other bad request type of code).
– plunntic iam
Nov 24 at 5:53
Anyway, my point was, that a request with invalid authorization is indeed bad / broken. Client assumes - for example - his authenticated as an admin, but api can't respond the way client assumes because authorization is invalid at this point. But responding with only the public data may be (and probably is) something totaly different than what the client expects. That's why i think api should respond with 400 (or with other bad request type of code).
– plunntic iam
Nov 24 at 5:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443355%2fproper-behaviour-for-publicly-available-api-resource-requested-using-expired-aut%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown