com.twitter.sdk.android.core.TwitterAuthToken Java Examples
The following examples show how to use
com.twitter.sdk.android.core.TwitterAuthToken.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OAuthControllerTest.java From twitter-kit-android with Apache License 2.0 | 6 votes |
@Test public void testNewAccessTokenCallback_success() { final Callback<OAuthResponse> callback = controller.newRequestAccessTokenCallback(); final OAuthResponse oAuthResponse = new OAuthResponse( new TwitterAuthToken(TestFixtures.TOKEN, TestFixtures.SECRET), TestFixtures.SCREEN_NAME, TestFixtures.USER_ID); callback.success(new Result<>(oAuthResponse, null)); final ArgumentCaptor<Intent> intentArgCaptor = ArgumentCaptor.forClass(Intent.class); verify(mockListener).onComplete(eq(Activity.RESULT_OK), intentArgCaptor.capture()); final Intent data = intentArgCaptor.getValue(); assertEquals(TestFixtures.SCREEN_NAME, data.getStringExtra(AuthHandler.EXTRA_SCREEN_NAME)); assertEquals(TestFixtures.USER_ID, data.getLongExtra(AuthHandler.EXTRA_USER_ID, 0L)); assertEquals(TestFixtures.TOKEN, data.getStringExtra(AuthHandler.EXTRA_TOKEN)); assertEquals(TestFixtures.SECRET, data.getStringExtra(AuthHandler.EXTRA_TOKEN_SECRET)); }
Example #2
Source File: AuthHandler.java From twitter-kit-android with Apache License 2.0 | 6 votes |
/** * Called when {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)} * is called to complete the authorization flow. * * @param requestCode the request code used for SSO * @param resultCode the result code returned by the SSO activity * @param data the result data returned by the SSO activity */ public boolean handleOnActivityResult(int requestCode, int resultCode, Intent data) { if (this.requestCode != requestCode) { return false; } final Callback<TwitterSession> callback = getCallback(); if (callback != null) { if (resultCode == Activity.RESULT_OK) { final String token = data.getStringExtra(EXTRA_TOKEN); final String tokenSecret = data.getStringExtra(EXTRA_TOKEN_SECRET); final String screenName = data.getStringExtra(EXTRA_SCREEN_NAME); final long userId = data.getLongExtra(EXTRA_USER_ID, 0L); callback.success(new Result<>(new TwitterSession( new TwitterAuthToken(token, tokenSecret), userId, screenName), null)); } else if (data != null && data.hasExtra(EXTRA_AUTH_ERROR)) { callback.failure( (TwitterAuthException) data.getSerializableExtra(EXTRA_AUTH_ERROR)); } else { callback.failure(new TwitterAuthException("Authorize failed.")); } } return true; }
Example #3
Source File: OAuth1aService.java From twitter-kit-android with Apache License 2.0 | 6 votes |
/** * @return {@link OAuthResponse} parsed from the * response, may be {@code null} if the response does not contain an auth token and secret. */ public static OAuthResponse parseAuthResponse(String response) { final TreeMap<String, String> params = UrlUtils.getQueryParams(response, false); final String token = params.get(OAuthConstants.PARAM_TOKEN); final String secret = params.get(OAuthConstants.PARAM_TOKEN_SECRET); final String userName = params.get(PARAM_SCREEN_NAME); final long userId; if (params.containsKey(PARAM_USER_ID)) { userId = Long.parseLong(params.get(PARAM_USER_ID)); } else { userId = 0L; } if (token == null || secret == null) { return null; } else { return new OAuthResponse(new TwitterAuthToken(token, secret), userName, userId); } }
Example #4
Source File: OAuth1aServiceTest.java From twitter-kit-android with Apache License 2.0 | 6 votes |
@Test public void testRequestAccessToken() { final TwitterAuthToken token = new TwitterAuthToken("token", "secret"); final String verifier = "verifier"; service.api = new MockOAuth1aService() { @Override public Call<ResponseBody> getAccessToken(@Header(OAuthConstants.HEADER_AUTHORIZATION) String auth, @Query(OAuthConstants.PARAM_VERIFIER) String innerVerifier) { assertEquals(verifier, innerVerifier); assertNotNull(auth); assertTrue(auth.contains(token.token)); return super.getAccessToken(auth, innerVerifier); } }; service.requestAccessToken(mock(Callback.class), token, verifier); }
Example #5
Source File: AuthHandlerTest.java From twitter-kit-android with Apache License 2.0 | 6 votes |
@Test public void testHandleOnActivityResult_resultCodeOK() { // Verify that when handleOnActivityResult is called with ok, the listener receives the auth // response. final Callback<TwitterSession> mockCallback = mock(Callback.class); final AuthHandler authHandler = newAuthHandler(mockCallback); final boolean result = authHandler.handleOnActivityResult(TEST_REQUEST_CODE, Activity.RESULT_OK, new Intent() .putExtra(AuthHandler.EXTRA_TOKEN, TestFixtures.TOKEN) .putExtra(AuthHandler.EXTRA_TOKEN_SECRET, TestFixtures.SECRET) .putExtra(AuthHandler.EXTRA_SCREEN_NAME, TestFixtures.SCREEN_NAME) .putExtra(AuthHandler.EXTRA_USER_ID, TestFixtures.USER_ID)); assertTrue(result); final ArgumentCaptor<Result> argCaptor = ArgumentCaptor.forClass(Result.class); verify(mockCallback).success(argCaptor.capture()); final TwitterSession session = (TwitterSession) argCaptor.getValue().data; final TwitterAuthToken authToken = session.getAuthToken(); assertEquals(TestFixtures.TOKEN, authToken.token); assertEquals(TestFixtures.SECRET, authToken.secret); assertEquals(TestFixtures.SCREEN_NAME, session.getUserName()); assertEquals(TestFixtures.USER_ID, session.getUserId()); }
Example #6
Source File: ComposerActivity.java From twitter-kit-android with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = getIntent(); final TwitterAuthToken token = intent.getParcelableExtra(EXTRA_USER_TOKEN); final TwitterSession session = new TwitterSession(token, PLACEHOLDER_ID, PLACEHOLDER_SCREEN_NAME); final Uri imageUri = intent.getParcelableExtra(EXTRA_IMAGE_URI); final String text = intent.getStringExtra(EXTRA_TEXT); final String hashtags = intent.getStringExtra(EXTRA_HASHTAGS); final int themeResId = intent.getIntExtra(EXTRA_THEME, R.style.ComposerLight); setTheme(themeResId); setContentView(R.layout.tw__activity_composer); final ComposerView composerView = findViewById(R.id.tw__composer_view); composerController = new ComposerController(composerView, session, imageUri, text, hashtags, new FinisherImpl()); }
Example #7
Source File: ComposerControllerTest.java From twitter-kit-android with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { mockComposerView = mock(ComposerView.class); mockContext = mock(Context.class); when(mockComposerView.getContext()).thenReturn(mockContext); mockFinisher = mock(ComposerActivity.Finisher.class); mockAuthToken = mock(TwitterAuthToken.class); mockTwitterSession = mock(TwitterSession.class); when(mockTwitterSession.getAuthToken()).thenReturn(mockAuthToken); final TwitterApiClient mockTwitterApiClient = mock(TwitterApiClient.class); mockAccountService = mock(AccountService.class); when(mockAccountService .verifyCredentials(any(Boolean.class), any(Boolean.class), any(Boolean.class))) .thenReturn(mock(Call.class)); when(mockTwitterApiClient.getAccountService()).thenReturn(mockAccountService); mockDependencyProvider = mock(ComposerController.DependencyProvider.class); when(mockDependencyProvider.getApiClient(any(TwitterSession.class))) .thenReturn(mockTwitterApiClient); when(mockDependencyProvider.getTweetValidator()).thenReturn(new Validator()); }
Example #8
Source File: TwitterNetwork.java From EasyLogin with MIT License | 6 votes |
@Override public void success(Result<TwitterSession> result) { TwitterSession session = result.data; TwitterAuthToken authToken = session.getAuthToken(); String token = authToken.token; String secret = authToken.secret; AccessToken tempToken = new AccessToken.Builder(token) .secret(secret) .userName(session.getUserName()) .userId(String.valueOf(session.getUserId())) .build(); if (additionalEmailRequest) { requestEmail(session, tempToken); } else { accessToken = tempToken; callLoginSuccess(); } }
Example #9
Source File: TweetUploadService.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Override protected void onHandleIntent(Intent intent) { final TwitterAuthToken token = intent.getParcelableExtra(EXTRA_USER_TOKEN); this.intent = intent; final TwitterSession twitterSession = new TwitterSession(token, PLACEHOLDER_ID, PLACEHOLDER_SCREEN_NAME); final String tweetText = intent.getStringExtra(EXTRA_TWEET_TEXT); final Uri imageUri = intent.getParcelableExtra(EXTRA_IMAGE_URI); uploadTweet(twitterSession, tweetText, imageUri); }
Example #10
Source File: LoginMaster.java From uPods-android with Apache License 2.0 | 5 votes |
public String getToken() { if (Prefs.getString(SyncMaster.GLOBAL_TOKEN, null) != null) { return Prefs.getString(SyncMaster.GLOBAL_TOKEN, null); } else if (AccessToken.getCurrentAccessToken() != null) return AccessToken.getCurrentAccessToken().getToken(); else if (Twitter.getSessionManager().getActiveSession() != null) { TwitterSession session = Twitter.getSessionManager().getActiveSession(); TwitterAuthToken authToken = session.getAuthToken(); return authToken.token; } else return VKAccessToken.currentToken().accessToken; }
Example #11
Source File: OAuthControllerTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Test public void testNewRequestTempTokenCallback_success() { final Callback<OAuthResponse> callback = controller.newRequestTempTokenCallback(); final TwitterAuthToken mockRequestToken = mock(TwitterAuthToken.class); final OAuthResponse oAuthResponse = new OAuthResponse(mockRequestToken, null, 0L); callback.success(new Result<>(oAuthResponse, null)); assertEquals(mockRequestToken, controller.requestToken); verify(mockOAuth1aService).getAuthorizeUrl(eq(mockRequestToken)); }
Example #12
Source File: ComposerActivityTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Before public void setUp() { mockContext = mock(Context.class); mockSession = mock(TwitterSession.class); mockAuthToken = mock(TwitterAuthToken.class); mockUri = Uri.EMPTY; when(mockSession.getAuthToken()).thenReturn(mockAuthToken); }
Example #13
Source File: OAuthResponseTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Test public void testParcelable() { final TwitterAuthToken authToken = new TwitterAuthToken(TestFixtures.TOKEN, TestFixtures.SECRET); final OAuthResponse authResponse = new OAuthResponse(authToken, TestFixtures.SCREEN_NAME, TestFixtures.USER_ID); final Parcel parcel = Parcel.obtain(); authResponse.writeToParcel(parcel, 0); parcel.setDataPosition(0); final OAuthResponse parceledAuthResponse = OAuthResponse.CREATOR.createFromParcel(parcel); assertEquals(authResponse.authToken, parceledAuthResponse.authToken); assertEquals(TestFixtures.SCREEN_NAME, parceledAuthResponse.userName); assertEquals(TestFixtures.USER_ID, parceledAuthResponse.userId); }
Example #14
Source File: OAuth1aHeadersTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Test public void testGetAuthorizationHeader() throws Exception { final TwitterAuthConfig config = mock(TwitterAuthConfig.class); final TwitterAuthToken token = mock(TwitterAuthToken.class); assertEquals(ANY_AUTH_CREDENTIALS, oAuthHeaders.getAuthorizationHeader(config, token, null, "GET", VERIFY_CREDENTIALS_URL, null)); }
Example #15
Source File: OAuth1aHeadersTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Test public void testGetOAuthEchoHeaders() throws Exception { final TwitterAuthConfig config = mock(TwitterAuthConfig.class); final TwitterAuthToken token = mock(TwitterAuthToken.class); final Map<String, String> headers = oAuthHeaders.getOAuthEchoHeaders(config, token, null, "GET", VERIFY_CREDENTIALS_URL, null); assertEquals(VERIFY_CREDENTIALS_URL, headers.get(OAuth1aHeaders .HEADER_AUTH_SERVICE_PROVIDER)); assertEquals(ANY_AUTH_CREDENTIALS, headers.get(OAuth1aHeaders .HEADER_AUTH_CREDENTIALS)); }
Example #16
Source File: TweetUploadServiceTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Test public void testOnHandleIntent() { final TwitterAuthToken mockToken = mock(TwitterAuthToken.class); final Intent intent = new Intent(context, TweetUploadService.class); intent.putExtra(TweetUploadService.EXTRA_USER_TOKEN, mockToken); intent.putExtra(TweetUploadService.EXTRA_TWEET_TEXT, EXPECTED_TWEET_TEXT); intent.putExtra(TweetUploadService.EXTRA_IMAGE_URI, Uri.EMPTY); service.onHandleIntent(intent); verify(service).uploadTweet(any(TwitterSession.class), eq(EXPECTED_TWEET_TEXT), eq(Uri.EMPTY)); }
Example #17
Source File: RNDigits.java From react-native-digits with MIT License | 5 votes |
@ReactMethod public void view(final Callback cb) { authCallback = new AuthCallback() { @Override public void success(DigitsSession session, String phoneNumber){ WritableMap auth = Arguments.createMap(); Digits digits = Digits.getInstance(); TwitterAuthConfig config = digits.getAuthConfig(); auth.putString("consumerKey", config.getConsumerKey()); auth.putString("consumerSecret", config.getConsumerSecret()); TwitterAuthToken token = (TwitterAuthToken)session.getAuthToken(); auth.putString("authToken", token.token); auth.putString("authTokenSecret", token.secret); Long id = session.getId(); auth.putString("userId", String.valueOf(id)); auth.putString("phoneNumber", session.getPhoneNumber()); cb.invoke(null, auth); } @Override public void failure(DigitsException error) { cb.invoke(error.getLocalizedMessage(), null); } }; int themeId = mContext.getResources().getIdentifier("CustomDigitsTheme", "style", mContext.getPackageName()); DigitsAuthConfig.Builder digitsAuthConfigBuilder = new DigitsAuthConfig.Builder() .withAuthCallBack(authCallback) .withPhoneNumber("") .withThemeResId(themeId); Digits.authenticate(digitsAuthConfigBuilder.build()); }
Example #18
Source File: LoginMaster.java From uPods-android with Apache License 2.0 | 5 votes |
public String getSecret() { if (Twitter.getSessionManager().getActiveSession() != null) { TwitterSession session = Twitter.getSessionManager().getActiveSession(); TwitterAuthToken authToken = session.getAuthToken(); return authToken.secret; } return ""; }
Example #19
Source File: OAuth1aService.java From twitter-kit-android with Apache License 2.0 | 5 votes |
/** * @param requestToken The request token. * @return authorization url that can be used to get a verifier code to get access token. */ public String getAuthorizeUrl(TwitterAuthToken requestToken) { // https://api.twitter.com/oauth/authorize?oauth_token=%s return getApi().buildUponBaseHostUrl(RESOURCE_OAUTH, "authorize") .appendQueryParameter(OAuthConstants.PARAM_TOKEN, requestToken.token) .build() .toString(); }
Example #20
Source File: OAuth1aService.java From twitter-kit-android with Apache License 2.0 | 5 votes |
/** * Requests a Twitter access token to act on behalf of a user account. * * @param callback The callback interface to invoke when when the request completes. */ public void requestAccessToken(final Callback<OAuthResponse> callback, TwitterAuthToken requestToken, String verifier) { final String url = getAccessTokenUrl(); final String authHeader = new OAuth1aHeaders().getAuthorizationHeader(getTwitterCore() .getAuthConfig(), requestToken, null, "POST", url, null); api.getAccessToken(authHeader, verifier).enqueue(getCallbackWrapper(callback)); }
Example #21
Source File: OAuth1aHeaders.java From twitter-kit-android with Apache License 2.0 | 5 votes |
/** * @param authConfig The auth config. * @param authToken The auth token to use. * @param callback The callback url. * @param method The HTTP method (GET, POST, PUT, DELETE, etc). * @param url The url delegation should be sent to (e.g. https://api.twitter.com/1.1/account/verify_credentials.json). * @param postParams The post parameters. * @return A map of OAuth Echo headers */ public Map<String, String> getOAuthEchoHeaders(TwitterAuthConfig authConfig, TwitterAuthToken authToken, String callback, String method, String url, Map<String, String> postParams) { final Map<String, String> headers = new HashMap<>(2); final String authorizationHeader = getAuthorizationHeader(authConfig, authToken, callback, method, url, postParams); headers.put(HEADER_AUTH_CREDENTIALS, authorizationHeader); headers.put(HEADER_AUTH_SERVICE_PROVIDER, url); return headers; }
Example #22
Source File: OkHttpClientHelper.java From twitter-kit-android with Apache License 2.0 | 5 votes |
public static OkHttpClient getOkHttpClient(Session<? extends TwitterAuthToken> session, TwitterAuthConfig authConfig) { if (session == null) { throw new IllegalArgumentException("Session must not be null."); } return addSessionAuth(new OkHttpClient.Builder(), session, authConfig).build(); }
Example #23
Source File: OAuth1aParameters.java From twitter-kit-android with Apache License 2.0 | 5 votes |
OAuth1aParameters(TwitterAuthConfig authConfig, TwitterAuthToken authToken, String callback, String method, String url, Map<String, String> postParams) { this.authConfig = authConfig; this.authToken = authToken; this.callback = callback; this.method = method; this.url = url; this.postParams = postParams; }
Example #24
Source File: OkHttpClientHelper.java From twitter-kit-android with Apache License 2.0 | 5 votes |
static OkHttpClient.Builder addSessionAuth(OkHttpClient.Builder builder, Session<? extends TwitterAuthToken> session, TwitterAuthConfig authConfig) { return builder .certificatePinner(getCertificatePinner()) .addInterceptor(new OAuth1aInterceptor(session, authConfig)); }
Example #25
Source File: OkHttpClientHelper.java From twitter-kit-android with Apache License 2.0 | 5 votes |
public static OkHttpClient getCustomOkHttpClient( OkHttpClient httpClient, Session<? extends TwitterAuthToken> session, TwitterAuthConfig authConfig) { if (session == null) { throw new IllegalArgumentException("Session must not be null."); } if (httpClient == null) { throw new IllegalArgumentException("HttpClient must not be null."); } return addSessionAuth(httpClient.newBuilder(), session, authConfig) .build(); }
Example #26
Source File: OAuthResponse.java From twitter-kit-android with Apache License 2.0 | 4 votes |
public OAuthResponse(TwitterAuthToken authToken, String userName, long userId) { this.authToken = authToken; this.userName = userName; this.userId = userId; }
Example #27
Source File: LoginActivity.java From Pharmacy-Android with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); ButterKnife.bind(this); mAnalytics = FirebaseAnalytics.getInstance(this); mAnimator = new ObjectAnimator(); mIconAnimation =(Animator) AnimatorInflater.loadAnimator(this, R.animator.icon_loading_rotate); mIconAnimation.setTarget(appIconImageView); // final DigitsAuthButton authButton = (DigitsAuthButton) findViewById(R.id.button_auth); authButton.setAuthTheme(R.style.AppTheme); authButton.setText("Login"); authButton.setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary)); authButton.setCallback(new AuthCallback() { @Override public void success(DigitsSession session, String phoneNumber) { // Log.d(TAG, "success: ph no: " + phoneNumber); // Log.d(TAG, "Auth token" + session.getAuthToken()); TwitterAuthConfig authConfig = TwitterCore.getInstance().getAuthConfig(); mPhoneNumber = session.getPhoneNumber(); DigitsOAuthSigning oAuthSigning = new DigitsOAuthSigning(authConfig, (TwitterAuthToken) session.getAuthToken()); Map<String, String> authHeaders = oAuthSigning.getOAuthEchoHeadersForVerifyCredentials(); doLogin(authHeaders); // Toast.makeText(LoginActivity.this, "Phone no: " + session.getPhoneNumber(), Toast.LENGTH_SHORT).show(); } @Override public void failure(DigitsException error) { showLoginError(); } }); }
Example #28
Source File: TwitterActivity.java From PracticeDemo with Apache License 2.0 | 4 votes |
private void setUpTwitterButton() { mBtnTwitter.setCallback(new Callback<TwitterSession>() {//userName alancheen06 secret 4H6cMSpc59EbLSlcQ5QI0SzAUXAAZnxDZ40KUqQkJkl7s token 3313987080-L3UPicTGjEZrNjpjsobeDQRCbWGFyczUCV2O408 @Override public void success(Result<TwitterSession> result) { Log.d("Twitter", "success() called with: " + "result = [" + result + "]++++data" + result.data); String name = result.data.getUserName(); long userId = result.data.getUserId();//3313987080 long id = result.data.getId(); TwitterAuthToken token = result.data.getAuthToken(); String secret = token.secret; String strToken = token.token; // TypedInput input = result.response.getBody(); Notice result.response为null // input.length(); // input.mimeType(); // String url = result.response.getUrl(); // String reason = result.response.getReason(); // int status = result.response.getStatus(); // List<Header> header = result.response.getHeaders(); StringBuilder sb = new StringBuilder(); sb.append("\nTwitter success:") .append("name:") .append(name + "\n") .append("userId:") .append(userId + "\n") .append("id:") .append(id + "\n") .append("secret:") .append(secret + "\n") .append("strToken:") .append(strToken + "\n") ; Log.d("Twitter", sb.toString()); mTvResult.setText(sb.toString()); getInfo(token); } //Cannonball @Override public void failure(TwitterException exception) { Log.d("Twitter", "failure() called with: " + "exception = [" + exception.getMessage() + "]"); } }); }
Example #29
Source File: OAuth1aInterceptor.java From twitter-kit-android with Apache License 2.0 | 4 votes |
public OAuth1aInterceptor(Session<? extends TwitterAuthToken> session, TwitterAuthConfig authConfig) { this.session = session; this.authConfig = authConfig; }
Example #30
Source File: OAuth1aHeadersTest.java From twitter-kit-android with Apache License 2.0 | 4 votes |
@Override OAuth1aParameters getOAuth1aParameters(TwitterAuthConfig authConfig, TwitterAuthToken authToken, String callback, String method, String url, Map<String, String> postParams) { return oAuth1aParameters; }