public Response register(@PathParam("appSecret") final String appSecret,
@FormParam("email") final String email,
@FormParam("username") final String username,
@FormParam("firstname") final String firstname,
@FormParam("lastname") final String lastname) throws IOException {
final Application application = partnerAppsService.getApplication(appSecret);
if (application==null)
return Responses.notFound().build();
if (!application.registrationAllowed)
return Response.status(Response.Status.FORBIDDEN).build();
try {
final Guest guest = guestService.createGuest(username, firstname, lastname, null, email, Guest.RegistrationMethod.REGISTRATION_METHOD_API, application.uid);
final AuthorizationToken authorizationToken = oAuth2MgmtService.issueAuthorizationToken(guest.getId(), application.getId());
TechnicalAuthorizationTokenModel authorizationTokenModel = new TechnicalAuthorizationTokenModel(authorizationToken, guest);
final String json = (new ObjectMapper()).writeValueAsString(authorizationTokenModel);
return Response.ok(json).build();
} catch (UsernameAlreadyTakenException e) {
return Response.status(Response.Status.BAD_REQUEST).entity("This username is already taken").build();