wso2 / product-is

Welcome to the WSO2 Identity Server source code! For info on working with the WSO2 Identity Server repository and contributing code, click the link below.
http://wso2.github.io/
Apache License 2.0
746 stars 724 forks source link

Inconsistent Error Responses in Device Flow #21192

Open shashimalcse opened 1 week ago

shashimalcse commented 1 week ago

Describe the issue: In the device flow, the token response is the same for multiple scenarios that should have distinct error codes according to the OAuth 2.0 Device Authorization Grant specification (RFC 8628).

Currently, the following scenarios all return the same error response:

The current error response for all these scenarios is:

{
   "error_description": "Error occurred while retrieving subject identifier for device code: 1a29b9d9-1d86-4f71-be32-202a1a29029c",
   "error": "invalid_grant"
}

How to reproduce:

Expected behavior: According to the specification, there should be distinct error codes for different scenarios:

Environment information (Please complete the following information; remove any unnecessary fields) :


Optional Fields

Related issues:

Suggested labels:

DMHP commented 3 days ago

https://github.com/wso2-extensions/identity-inbound-auth-oauth/pull/2587

DMHP commented 3 days ago

Manual Testing:

Success Case Request: curl -k -X POST -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:device_code' --data-urlencode 'client_id=bXwTdGpDuBC4kuOtecQvd_ue8Qka' --data-urlencode 'device_code=c031edad-7085-4c89-b6e0-c54a4834a2ec' https://localhost:9443/oauth2/token

Response: {"access_token":"2d859716-3fee-3f82-bd59-44fed93c6ff4","token_type":"Bearer","expires_in":3600}

When the authorization is pending Request: curl -k -X POST -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:device_code' --data-urlencode 'client_id=bXwTdGpDuBC4kuOtecQvd_ue8Qka' --data-urlencode 'device_code=acf10b14-b596-4cba-883f-4bb6256debbc' https://localhost:9443/oauth2/token

Response: {"error_description":"Precondition required","error":"authorization_pending"}

When the token is expired: Same request as above. Response: {"error_description":"Precondition required","error":"authorization_pending"}

When frequent requests sent before the polling interval Same request as above. Response: {"error_description":"Forbidden","error":"slow_down"}