基于OAuth安全协议的Java应用编程 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-16
accessor.requestToken); //Launch the browser and redirects user to authorization URL Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + authorizationURL); //wait for user''s authorization System.out.println("Please authorize your OAuth request token. " + "Once that is complete, press any key to continue..."); System.in.read(); oauthClient.getAccessToken(accessor, null, null); return accessor.accessToken; } } import java.net.URL; import java.security.KeyFactory; import java.security.PrivateKey; import java.security.spec.EncodedKeySpec; import java.security.spec.PKCS8EncodedKeySpec; import java.util.Collection; import java.util.Map; import com.google.gdata.client.GoogleService; import com.google.gdata.client.authn.oauth.OAuthParameters; import com.google.gdata.client.authn.oauth.OAuthRsaSha1Signer; import com.google.gdata.client.authn.oauth.OAuthSigner; import com.google.gdata.data.BaseEntry; import com.google.gdata.data.BaseFeed; import com.google.gdata.data.Feed; import net.oauth.OAuth; import net.oauth.OAuthConsumer; import net.oauth.OAuthMessage; import net.oauth.OAuthServiceProvider; import net.oauth.client.OAuthClient; import net.oauth.client.httpclient4.HttpClient4; import net.oauth.example.desktop.MyGoogleService; import net.oauth.signature.OAuthSignatureMethod; import net.oauth.signature.RSA_SHA1; public class GoogleOAuthExample { //Note, use the private key of your self-signed X509 certificate. private static final String PRIVATE_KEY = "XXXXXXXX"; public static void main(String[] args) throws Exception { KeyFactory fac = KeyFactory.getInstance("RSA"); //PRIVATE_KEY is the private key of your self-signed X509 certificate. EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec( OAuthSignatureMethod.decodeBase64(PRIVATE_KEY)); fac = KeyFactory.getInstance("RSA"); PrivateKey privateKey = fac.generatePrivate(privKeySpec); OAuthServiceProvider serviceProvider = new OAuthServiceProvider( //used for obtaining a request token //"https://www.google.com/accounts/OAuthGetRequestToken", //used for authorizing the request token "https://www.google.com/accounts/OAuthAuthorizeToken", //used for upgrading to an access token "https://www.google.com/accounts/OAuthGetAccessToken"); OAuthConsumer oauthConsumer = new OAuthConsumer(null , "lszhy.weebly.com" //consumer key , "hIsGnM+T4+86fKNesUtJq7Gs" //consumer secret , serviceProvider); oauthCo |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于基于OAuth安全协议的Java应用编程 - 编程入门网的所有评论