use of org.apache.oltu.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse in project BIMserver by opensourceBIM.
the class OAuthServiceImpl method registerApplication.
@Override
public Long registerApplication(String registrationEndpoint, String apiUrl, String redirectUrl) throws UserException, ServerException {
try {
try (DatabaseSession session = getBimServer().getDatabase().createSession()) {
OAuthServer oAuthServer = session.querySingle(StorePackage.eINSTANCE.getOAuthServer_RegistrationEndpoint(), registrationEndpoint);
if (oAuthServer != null) {
return oAuthServer.getOid();
}
ServerSettings serverSettings = getBimServer().getServerSettingsCache().getServerSettings();
OAuthClientRequest request = OAuthClientRegistrationRequest.location(registrationEndpoint, OAuthRegistration.Type.PUSH).setName(serverSettings.getName()).setUrl(redirectUrl).setDescription(serverSettings.getDescription()).setIcon(serverSettings.getIcon()).setRedirectURL(redirectUrl).buildJSONMessage();
OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new URLConnectionClient());
OAuthClientRegistrationResponse response = oauthclient.clientInfo(request);
oAuthServer = session.create(OAuthServer.class);
oAuthServer.setApiUrl(apiUrl);
oAuthServer.setClientId(response.getClientId());
oAuthServer.setClientSecret(response.getClientSecret());
oAuthServer.setIssuedAt(new Date(Long.parseLong(response.getIssuedAt())));
GregorianCalendar expiresAt = new GregorianCalendar();
expiresAt.setTimeInMillis(new GregorianCalendar().getTimeInMillis() + response.getExpiresIn());
oAuthServer.setExpiresAt(expiresAt.getTime());
oAuthServer.setRegistrationEndpoint(registrationEndpoint);
oAuthServer.setClientDescription(serverSettings.getDescription());
oAuthServer.setClientName(serverSettings.getName());
if (serverSettings.getIcon() != null) {
byte[] icon = NetUtils.getContentAsBytes(new URL(serverSettings.getIcon()), 500);
oAuthServer.setClientIcon(icon);
}
oAuthServer.setIncoming(false);
oAuthServer.setRedirectUrl(redirectUrl);
session.commit();
return oAuthServer.getOid();
}
} catch (Exception e) {
return handleException(e);
}
}
use of org.apache.oltu.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse in project BIMserver by opensourceBIM.
the class OAuthServiceImpl method registerRemoteApplication.
public SOAuthServer registerRemoteApplication(String redirectUrl, String name, String description) throws UserException {
try {
OAuthClientRequest request = OAuthClientRegistrationRequest.location(getBimServer().getServerSettingsCache().getServerSettings().getSiteAddress() + "/oauth/register/", OAuthRegistration.Type.PUSH).setName(name).setUrl(redirectUrl).setDescription(description).setRedirectURL(redirectUrl).buildJSONMessage();
OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new org.bimserver.webservices.impl.URLConnectionClient());
OAuthClientRegistrationResponse response = oauthclient.clientInfo(request);
SOAuthServer server = new SOAuthServer();
server.setClientId(response.getClientId());
server.setClientSecret(response.getClientSecret());
return server;
} catch (Exception e) {
throw new UserException(e);
}
}
use of org.apache.oltu.oauth2.ext.dynamicreg.client.response.OAuthClientRegistrationResponse in project BIMserver by opensourceBIM.
the class SendUrl method main.
public static void main(String[] args) {
try {
OAuthClientRequest request = OAuthClientRegistrationRequest.location("https://thisisanexperimentalserver.com/oauth/register/", OAuthRegistration.Type.PUSH).setName("Zapier").setUrl("https://zapier.com/dashboard/auth/oauth/return/App56192API").setDescription("App Description").setRedirectURL("https://zapier.com/dashboard/auth/oauth/return/App56192API").buildJSONMessage();
OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new org.bimserver.webservices.impl.URLConnectionClient());
OAuthClientRegistrationResponse response = oauthclient.clientInfo(request);
System.out.println(response.getClientId());
System.out.println(response.getClientSecret());
} catch (OAuthSystemException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (OAuthProblemException e) {
e.printStackTrace();
}
}
Aggregations