Why socialauth is giving class cast exception on provided parameter map?
SocialAuth getting started guide have following code sample:
// get the auth provider manager from session
SocialAuthManager manager = (SocialAuthManager)session.getAttribute("authM开发者_开发问答anager");
// call connect method of manager which returns the provider object.
// Pass request parameter map while calling connect method.
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();
The comment at line 3-4 say that we should pass the request parameter map to manager.connect()
. I tried:
manager.connect(request.getParameterMap());
But it gives
java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.lang.String
Should I create my own parameter map instead of passing map returned by request.getParameterMap()
?
Answering my own question:
The socialauth source have a sample with following code:
Map<String, String> paramsMap = SocialAuthUtil.getRequestParametersMap(request);
AuthProvider provider = manager.connect(paramsMap);
Which fixes the classcastexception
精彩评论