package org.oauth2.client; import java.util.Scanner; import org.junit.Test; import org.oauth2.client4j.builder.OAuthServiceBuilder; import org.oauth2.client4j.builder.provider.Provider; import org.oauth2.client4j.http.response.JSONAccessTokenResponse; import org.oauth2.client4j.service.OAuthService; public class OAuthCustomTest { public static final String KEY_ID = "09f9ec208d9a4d2c1dedc461a8cee784"; public static final String API_SECRET = "0fccff82381019f7"; public static final String REDIRECT_URL = "http://www.doubannote.org/oauth?type=douban"; private static final String AUTHOR_URL = "https://www.douban.com/service/auth2/auth"; private static final String TOKEN_URL = "https://www.douban.com/service/auth2/token"; //@Test public void test() { OAuthService service = new OAuthServiceBuilder() // .customHttpClient(new // HttpClient4(SSLUtils.createSSLInsecureClient())) .provider(new Provider() { @Override public String getAuthorizationEndpoint() { return AUTHOR_URL; } @Override public String getAccessTokenEndpoint() { return TOKEN_URL; } }).apiKey(KEY_ID).apiSecret(API_SECRET).callback(REDIRECT_URL) .build(); //extra parameter //service.getAuthorizationRequest().addParameter(name, value); System.out.println(service.getAuthorizationRequest().getLocationUri()); System.out.print("Input the code from your browser>>"); Scanner in = new Scanner(System.in); String code = in.nextLine(); in.close(); JSONAccessTokenResponse response = service.accessJsonToken(code); System.out.println(response.getAccessToken()); } }