开发者

java with Oauth for Google and facebook authontication

开发者 https://www.devze.com 2023-04-07 03:24 出处:网络
i wont to implement authentication using google and facebook in my application any one share example that work for authentication in java webapp

i wont to implement authentication using google and facebook in my application any one share example that work for authentication in java webapp without any java framework

i try with socialau开发者_JAVA技巧t its using struts and spring framework but i not use that framework in my application so give any example that work in simple tomcat application without any framework


add this code on login page request

 SocialAuthConfig config = SocialAuthConfig.getDefault();
  config.load(); // load your keys information 
  SocialAuthManager manager = new SocialAuthManager();
  manager.setSocialAuthConfig(config);

  String successUrl = "http://localhost:8080/yourapp/status
  String url = manager.getAuthenticationUrl("facebook", successUrl);
  session.setAttribute("authManager", manager);

redirect yout page to url for authentication

add this code on /status url

SocialAuthManager manager = (SocialAuthManager)session.getAttribute("authManager");

   AuthProvider provider = manager.connect(paramsMap);

  // get profile
  Profile p = provider.getUserProfile();

  // you can obtain profile information
  System.out.println(p.getFirstName());

  // OR also obtain list of contacts
  List<Contact> contactsList = provider.getContactList();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号