2016-04-25 8 views
0

私は、Oauth2認証(パスワード付与タイプ)を使用して動作するSpringブートアプリケーションを持っています。私は今FacebookとTwitterのログインをサポートする必要があります。春のソーシャルでのTwitterのログイン

カスタムTokenGranterを使用して、クライアントが私のFacebookアプリケーショントークンまたはTwitterのコンシューマIDとシークレットを私に送信して、自分のサーバーアプリケーションにログインし、生成するOAuth2 access_tokenを受け取れるようにしています。私はこのFacebookConnectionFactory使用してFacebookのために働いています。接続して

Connection<Facebook> connection = facebookConnectionFactory.createConnection(new AccessGrant(providerToken)); 

、私はFacebookののユーザIDを取得:このIDの

String providerUserId = connection.getKey().getProviderUserId(); 

を、私は検索し、ユーザーは自分のUserRepositoryに存在する場合そうであれば、私はユーザーにログインします:

CustomUserDetails userDetails = new CustomUserDetails(user); 
userAuth = new SocialAuthenticationToken(connection, userDetails, 
               null, userDetails.getAuthorities()); 
SecurityContextHolder.getContext().setAuthentication(userAuth); 

これはすべて正常に動作します。ツイッターで同じことをやって:

Connection<Twitter> connection = twitterConnectionFactory.createConnection(new OAuthToken(providerToken, tokenSecret)); 

は私にこの例外を与える:

Unable to connect with Twitter: Authorization is required for the operation, 
but the API binding was created without authorization. 

私は奇妙見つける何をすると、同じアプリケーションIDと秘密と消費者と消費者の秘密とTwitterTemplateを使用して作業を行うということです。

TwitterTemplate twitterTemplate = new TwitterTemplate(...); 
UserOperations userOperations = twitterTemplate.userOperations(); 
AccountSettings accountSettings = userOperations.getAccountSettings(); 

私はSocialAuthenticationTokenためConnection<Twitter>オブジェクトが必要です。私は間違って何をしていますか?

答えて

0

愚かな間違い、私が持っていた:の代わりに

@Value("spring.social.twitter.app-id") 
private String twitterAppId; 
@Value("spring.social.twitter.app-secret") 
private String twitterAppSecret; 

@Value("${spring.social.twitter.app-id}") 
private String twitterAppId; 
@Value("${spring.social.twitter.app-secret}") 
private String twitterAppSecret; 

をだから私はリテラルテキストspring.social.twitter.app-id代わりのプロパティの値を入れます。

関連する問題