'Why?????'에 해당되는 글 1건

  1. 2017.02.02 OAuth 2.0 에서 비밀번호가 틀렸느데 왜 400 에러가?

OAuth 2.0 과련 서비스를 만들어 테스트하는 도중에 ID/PWD 를 이용한 사용자 인증시 비밀번호가 틀렸을 경우 error : invalid_grant 에러가 발생하는데 이때 HTTP Status 가 400 으로 반환된다.


400 !?


내가 알기론 400 Status 는 Bad Request 인데, client 에서 잘못된 요청이 있을 경우 발생하는 경우라 클라이언트의 요청부분을 수정해야 할 경우 발생시키는 에러로 인지하고 있는데, 비밀번호가 틀렸을 경우 400 에러를 발생시키는게 좀 의아했다.


비밀번호가 틀렸으니 401(Unauthorized) 상태를 반환해야하는것이 맞지 않을까?


그래서 문제를 제기했는데, OAuth 2.0 관련 라이브러리에서 자동으로 그렇게 만들어 주는 부분이라한다. 

관련 이슈를 조사해보니 정말 invalid_grant is 400 이었다.


라이브러리 부분을 뜯어 고치기엔 일이 커지는지라 일단 그대로 400 으로 인지 하자곤 했는데...

계속 "왜??" 라는 의문이 계속 남는다.


언제 관련 부분 조사를 좀 해봐야할듯해서 기록을 남긴다.


덧. 


# Stackoverflow 에서도 나와 유사한 의문을 가진 사람이 있었군..


http://stackoverflow.com/questions/22586825/oauth-2-0-why-does-the-authorization-server-return-400-instead-of-401-when-the


# 여기 스펙에서는 invalid_grant is 401 이다.


https://www.tutorialspoint.com/oauth2.0/error_response_codes.htm



# OAuth2 flows


http://apiwiki.poken.com/authentication/oauth2


# OAuth2 Response Codes


https://www.docusign.com/p/RESTAPIGuide/Content/OAuth2/OAuth2%20Response%20Codes.htm


OAuth2 Response Codes

The OAuth2 –related endpoints return 200-OK on success. On failure, they typically return 400-Bad Request, or 401-Unauthorized.

In order to be consistent with OAuth2 documentation, the OAuth2-related endpoints support a different error response format than other DocuSign REST API calls. The body of an error response to the “oauth2/token” and “oauth2/revoke” endpoints have the format:

{

"error":"<error code>",

"error_description":"<optional description>"

}

 

Oauth2/token Endpoint error codes:

Error code values are all lower-case to match OAuth2 documentation.

Error CodeError Description
invalid_requestThe request was malformed, or contains unsupported parameters
invalid_clientThe client authentication failed.
invalid_grantThe provided authorization is invalid.
unauthorized_clientThe client application is not allowed to use this grant_type.
unsupported_grant_typeA grant_type other than “password” was used in the request.
invalid_scopeThe scope was not set to “api”.

 

OAuth2/revoke Endpoint error codes

Error code values are all lower-case to match OAuth2 documentation.

Error CodeError Description
unsupported_token_typeThe client tried to revoke an access token on a server not supporting this feature. This error is not supported in DocuSign.
invalid_tokenThe presented token is invalid.

 



Posted by CJ.Ree
,