Added api service
This commit is contained in:
52
buisnesslogic/src/main/java/com/plannaplan/api/UsosOauth1Service.java
Executable file
52
buisnesslogic/src/main/java/com/plannaplan/api/UsosOauth1Service.java
Executable file
@ -0,0 +1,52 @@
|
||||
package com.plannaplan.api;
|
||||
|
||||
import com.github.scribejava.core.builder.api.DefaultApi10a;
|
||||
|
||||
public class UsosOauth1Service extends DefaultApi10a {
|
||||
|
||||
private static final String AUTHORIZE_URL = "https://usosapidemo.amu.edu.pl/services/oauth/authorize";
|
||||
private static final String REQUEST_TOKEN_URL = "https://usosapidemo.amu.edu.pl/services/oauth/request_token";
|
||||
|
||||
private final String scopesAsString;
|
||||
|
||||
protected UsosOauth1Service() {
|
||||
scopesAsString = null;
|
||||
}
|
||||
|
||||
protected UsosOauth1Service(String... scopes) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (String scope : scopes) {
|
||||
builder.append('+').append(scope);
|
||||
}
|
||||
scopesAsString = "?scope=" + builder.substring(1);
|
||||
}
|
||||
|
||||
private static class InstanceHolder {
|
||||
|
||||
private static final UsosOauth1Service INSTANCE = new UsosOauth1Service();
|
||||
}
|
||||
|
||||
public static UsosOauth1Service instance() {
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public static UsosOauth1Service instance(String... scopes) {
|
||||
return scopes == null || scopes.length == 0 ? instance() : new UsosOauth1Service(scopes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequestTokenEndpoint() {
|
||||
return scopesAsString == null ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + scopesAsString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessTokenEndpoint() {
|
||||
return "https://usosapidemo.amu.edu.pl/services/oauth/access_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAuthorizationBaseUrl() {
|
||||
return AUTHORIZE_URL;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user