use of oauth2.common.ConsumerRegistration in project tesb-rt-se by Talend.
the class ThirdPartyRegistrationService method register.
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/")
public ConsumerRegistration register(MultipartBody body) {
String appName = body.getAttachmentObject("appName", String.class);
String appURI = body.getAttachmentObject("appURI", String.class);
String appRedirectURI = body.getAttachmentObject("appRedirectURI", String.class);
String appDesc = body.getAttachmentObject("appDescription", String.class);
URI logoURI = null;
Attachment att = body.getAttachment("appLogo");
if (att != null) {
InputStream logoStream = att.getObject(InputStream.class);
CachedOutputStream cos = new CachedOutputStream();
try {
IOUtils.copy(logoStream, cos);
appLogos.put(appName.toLowerCase(), cos);
UriBuilder ub = uriInfo.getAbsolutePathBuilder();
ub.path("logo").path(appName.toLowerCase());
ContentDisposition cd = att.getContentDisposition();
if (cd != null && cd.getParameter("filename") != null) {
ub.path(cd.getParameter("filename"));
}
logoURI = ub.build();
} catch (IOException ex) {
// ignore
}
}
String clientId = generateClientId(appName, appURI);
String clientSecret = generateClientSecret();
Client newClient = new Client(clientId, clientSecret, true, appName, appURI);
newClient.setApplicationDescription(appDesc);
newClient.setApplicationLogoUri(logoURI.toString());
newClient.setRedirectUris(Collections.singletonList(appRedirectURI));
manager.registerClient(newClient);
return new ConsumerRegistration(clientId, clientSecret);
}
use of oauth2.common.ConsumerRegistration in project tesb-rt-se by Talend.
the class ThirdPartyRegistrationService method registerForm.
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("/")
public ConsumerRegistration registerForm(@FormParam("appName") String appName, @FormParam("appURI") String appURI, @FormParam("appRedirectURI") String appRedirectURI) {
String clientId = generateClientId(appName, appURI);
String clientSecret = generateClientSecret();
Client newClient = new Client(clientId, clientSecret, true, appName, appURI);
newClient.setRedirectUris(Collections.singletonList(appRedirectURI));
manager.registerClient(newClient);
return new ConsumerRegistration(clientId, clientSecret);
}
Aggregations