Skip to content

Commit

Permalink
Resolving comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DMHP committed Oct 11, 2024
1 parent 0545870 commit eac5a95
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
import java.sql.Timestamp;
import java.util.Date;

import static org.wso2.carbon.identity.oauth2.device.constants.Constants.PENDING;
import static org.wso2.carbon.identity.oauth2.device.constants.Constants.SLOW_DOWN;

/**
* Device flow grant type for Identity Server.
*/
Expand Down Expand Up @@ -76,16 +73,19 @@ public boolean validateGrant(OAuthTokenReqMessageContext oAuthTokenReqMessageCon
} catch (IdentityOAuth2Exception e) {
deviceStatus = e.getMessage();
setLastPollTime(deviceCode);
handleInvalidRequests(deviceStatus);
handleInvalidRequests(e);
}

handleInvalidRequests(deviceStatus, deviceFlowDO);
if (Constants.AUTHORIZED.equals(deviceStatus)) {
DeviceFlowPersistenceFactory.getInstance().getDeviceFlowDAO().setDeviceCodeExpired(deviceCode,
Constants.EXPIRED);
setPropertiesForTokenGeneration(oAuthTokenReqMessageContext, deviceFlowDO);
if (deviceFlowDO != null) {
setPropertiesForTokenGeneration(oAuthTokenReqMessageContext, deviceFlowDO);
return true;
}
}
return true;
return false;
}

private void setLastPollTime(String deviceCode)
Expand All @@ -108,15 +108,17 @@ private void handleInvalidRequests(String deviceStatus, DeviceFlowDO deviceFlowD
}
}

private void handleInvalidRequests(String deviceStatus) throws IdentityOAuth2Exception {
private void handleInvalidRequests(IdentityOAuth2Exception e) throws IdentityOAuth2Exception {

if (PENDING.equals(deviceStatus)) {
String deviceStatus = e.getMessage();
if (Constants.PENDING.equals(deviceStatus)) {
throw new IdentityOAuth2Exception(DeviceErrorCodes.SubDeviceErrorCodes.AUTHORIZATION_PENDING,
DeviceErrorCodes.SubDeviceErrorCodesDescriptions.AUTHORIZATION_PENDING);
} else if (SLOW_DOWN.equals(deviceStatus)) {
} else if (Constants.SLOW_DOWN.equals(deviceStatus)) {
throw new IdentityOAuth2Exception(DeviceErrorCodes.SubDeviceErrorCodes.SLOW_DOWN,
DeviceErrorCodes.SubDeviceErrorCodesDescriptions.SLOW_DOWN);
}
throw e;
}

/**
Expand Down

0 comments on commit eac5a95

Please sign in to comment.