私は、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>
オブジェクトが必要です。私は間違って何をしていますか?