|
|
|
@ -16,6 +16,8 @@
|
|
|
|
|
|
|
|
|
|
package org.mitre.oauth2.web; |
|
|
|
|
|
|
|
|
|
import java.net.URI; |
|
|
|
|
import java.net.URISyntaxException; |
|
|
|
|
import java.util.Collection; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.HashMap; |
|
|
|
@ -26,6 +28,7 @@ import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpSession; |
|
|
|
|
|
|
|
|
|
import org.apache.http.client.utils.URIBuilder; |
|
|
|
|
import org.mitre.oauth2.exception.DeviceCodeCreationException; |
|
|
|
|
import org.mitre.oauth2.model.ClientDetailsEntity; |
|
|
|
|
import org.mitre.oauth2.model.DeviceCode; |
|
|
|
@ -143,6 +146,14 @@ public class DeviceEndpoint {
|
|
|
|
|
response.put("expires_in", client.getDeviceCodeValiditySeconds()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (config.isAllowCompleteDeviceCodeUri()) { |
|
|
|
|
URI verificationUriComplete = new URIBuilder(config.getIssuer() + USER_URL) |
|
|
|
|
.addParameter("user_code", dc.getUserCode()) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
response.put("verification_uri_complete", verificationUriComplete.toString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
model.put(JsonEntityView.ENTITY, response); |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -154,18 +165,31 @@ public class DeviceEndpoint {
|
|
|
|
|
model.put(JsonErrorView.ERROR_MESSAGE, dcce.getMessage()); |
|
|
|
|
|
|
|
|
|
return JsonErrorView.VIEWNAME; |
|
|
|
|
} catch (URISyntaxException use) { |
|
|
|
|
logger.error("unable to build verification_uri_complete due to wrong syntax of uri components"); |
|
|
|
|
model.put(HttpCodeView.CODE, HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
|
|
|
|
|
|
return HttpCodeView.VIEWNAME; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@PreAuthorize("hasRole('ROLE_USER')") |
|
|
|
|
@RequestMapping(value = "/" + USER_URL, method = RequestMethod.GET) |
|
|
|
|
public String requestUserCode(ModelMap model) { |
|
|
|
|
public String requestUserCode(@RequestParam(value = "user_code", required = false) String userCode, ModelMap model, HttpSession session) { |
|
|
|
|
|
|
|
|
|
if (!config.isAllowCompleteDeviceCodeUri() || userCode == null) { |
|
|
|
|
// if we don't allow the complete URI or we didn't get a user code on the way in,
|
|
|
|
|
// print out a page that asks the user to enter their user code
|
|
|
|
|
// user must be logged in
|
|
|
|
|
|
|
|
|
|
return "requestUserCode"; |
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
// complete verification uri was used, we received user code directly
|
|
|
|
|
// skip requesting code page
|
|
|
|
|
// user must be logged in
|
|
|
|
|
return readUserCode(userCode, model, session); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@PreAuthorize("hasRole('ROLE_USER')") |
|
|
|
|