keycloak-service
公開メンバ関数 | 限定公開変数類 | 非公開メンバ関数 | 全メンバ一覧
org.keycloak.social.twitter.TwitterIdentityProvider.Endpoint クラス
org.keycloak.social.twitter.TwitterIdentityProvider.Endpoint 連携図
Collaboration graph

公開メンバ関数

 Endpoint (RealmModel realm, AuthenticationCallback callback, EventBuilder event)
 
Response authResponse (@QueryParam("state") String state, @QueryParam("denied") String denied, @QueryParam("oauth_verifier") String verifier)
 

限定公開変数類

RealmModel realm
 
AuthenticationCallback callback
 
EventBuilder event
 
KeycloakSession session
 
ClientConnection clientConnection
 
HttpHeaders headers
 

非公開メンバ関数

void sendErrorEvent ()
 

詳解

構築子と解体子

◆ Endpoint()

org.keycloak.social.twitter.TwitterIdentityProvider.Endpoint.Endpoint ( RealmModel  realm,
AuthenticationCallback  callback,
EventBuilder  event 
)
inline
176  {
177  this.realm = realm;
178  this.callback = callback;
179  this.event = event;
180  }
AuthenticationCallback callback
Definition: TwitterIdentityProvider.java:164
RealmModel realm
Definition: TwitterIdentityProvider.java:163
EventBuilder event
Definition: TwitterIdentityProvider.java:165

関数詳解

◆ authResponse()

Response org.keycloak.social.twitter.TwitterIdentityProvider.Endpoint.authResponse ( @QueryParam("state") String  state,
@QueryParam("denied") String  denied,
@QueryParam("oauth_verifier") String  verifier 
)
inline
185  {
186  if (denied != null) {
187  return callback.cancelled(state);
188  }
189 
190  AuthenticationSessionModel authSession = null;
191  try {
192  Twitter twitter = new TwitterFactory().getInstance();
193 
194  twitter.setOAuthConsumer(getConfig().getClientId(), getConfig().getClientSecret());
195 
196  IdentityBrokerState idpState = IdentityBrokerState.encoded(state);
197  String clientId = idpState.getClientId();
198  String tabId = idpState.getTabId();
199  if (clientId == null || tabId == null) {
200  logger.errorf("Invalid state parameter: %s", state);
201  sendErrorEvent();
202  return ErrorPage.error(session, null, Response.Status.BAD_REQUEST, Messages.INVALID_REQUEST);
203  }
204 
205  ClientModel client = realm.getClientByClientId(clientId);
206  authSession = ClientSessionCode.getClientSession(state, tabId, session, realm, client, event, AuthenticationSessionModel.class);
207 
208  String twitterToken = authSession.getAuthNote(TWITTER_TOKEN);
209  String twitterSecret = authSession.getAuthNote(TWITTER_TOKENSECRET);
210 
211  RequestToken requestToken = new RequestToken(twitterToken, twitterSecret);
212 
213  AccessToken oAuthAccessToken = twitter.getOAuthAccessToken(requestToken, verifier);
214  twitter4j.User twitterUser = twitter.verifyCredentials();
215 
216  BrokeredIdentityContext identity = new BrokeredIdentityContext(Long.toString(twitterUser.getId()));
217  identity.setIdp(TwitterIdentityProvider.this);
218 
219  identity.setUsername(twitterUser.getScreenName());
220  identity.setName(twitterUser.getName());
221 
222 
223  StringBuilder tokenBuilder = new StringBuilder();
224 
225  tokenBuilder.append("{");
226  tokenBuilder.append("\"oauth_token\":").append("\"").append(oAuthAccessToken.getToken()).append("\"").append(",");
227  tokenBuilder.append("\"oauth_token_secret\":").append("\"").append(oAuthAccessToken.getTokenSecret()).append("\"").append(",");
228  tokenBuilder.append("\"screen_name\":").append("\"").append(oAuthAccessToken.getScreenName()).append("\"").append(",");
229  tokenBuilder.append("\"user_id\":").append("\"").append(oAuthAccessToken.getUserId()).append("\"");
230  tokenBuilder.append("}");
231  String token = tokenBuilder.toString();
232  if (getConfig().isStoreToken()) {
233  identity.setToken(token);
234  }
235  identity.getContextData().put(IdentityProvider.FEDERATED_ACCESS_TOKEN, token);
236 
237  identity.setIdpConfig(getConfig());
238  identity.setCode(state);
239 
240  return callback.authenticated(identity);
241  } catch (WebApplicationException e) {
242  sendErrorEvent();
243  return e.getResponse();
244  } catch (Exception e) {
245  logger.error("Couldn't get user profile from twitter.", e);
246  sendErrorEvent();
247  return ErrorPage.error(session, authSession, Response.Status.BAD_GATEWAY, Messages.UNEXPECTED_ERROR_HANDLING_RESPONSE);
248  }
249  }
AuthenticationCallback callback
Definition: TwitterIdentityProvider.java:164
static final String TWITTER_TOKENSECRET
Definition: TwitterIdentityProvider.java:73
KeycloakSession session
Definition: TwitterIdentityProvider.java:168
static final String TWITTER_TOKEN
Definition: TwitterIdentityProvider.java:72
RealmModel realm
Definition: TwitterIdentityProvider.java:163
EventBuilder event
Definition: TwitterIdentityProvider.java:165
void sendErrorEvent()
Definition: TwitterIdentityProvider.java:251
static final Logger logger
Definition: TwitterIdentityProvider.java:70
TwitterIdentityProvider(KeycloakSession session, OAuth2IdentityProviderConfig config)
Definition: TwitterIdentityProvider.java:75

◆ sendErrorEvent()

void org.keycloak.social.twitter.TwitterIdentityProvider.Endpoint.sendErrorEvent ( )
inlineprivate
251  {
252  event.event(EventType.LOGIN);
253  event.error("twitter_login_failed");
254  }

メンバ詳解

◆ callback

AuthenticationCallback org.keycloak.social.twitter.TwitterIdentityProvider.Endpoint.callback
protected

◆ clientConnection

ClientConnection org.keycloak.social.twitter.TwitterIdentityProvider.Endpoint.clientConnection
protected

◆ event

EventBuilder org.keycloak.social.twitter.TwitterIdentityProvider.Endpoint.event
protected

◆ headers

HttpHeaders org.keycloak.social.twitter.TwitterIdentityProvider.Endpoint.headers
protected

◆ realm

RealmModel org.keycloak.social.twitter.TwitterIdentityProvider.Endpoint.realm
protected

◆ session

KeycloakSession org.keycloak.social.twitter.TwitterIdentityProvider.Endpoint.session
protected

このクラス詳解は次のファイルから抽出されました: