com.twitter.sdk.android.core.TwitterAuthConfig Java Examples

The following examples show how to use com.twitter.sdk.android.core.TwitterAuthConfig. 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: ReactTwitterKitPackage.java    From react-native-twitterkit with MIT License 6 votes vote down vote up
public void initFabric(Context reactContext) {
  if (consumerKey == null || consumerSecret == null) {
    return;
  }

  TwitterAuthConfig authConfig
          = new TwitterAuthConfig(consumerKey, consumerSecret);

  final TwitterConfig config = new TwitterConfig.Builder(reactContext)
          .twitterAuthConfig(authConfig)
          .debug(true)
          .build();
  Twitter.initialize(config);
  new Thread(new Runnable() {
    @Override
    public void run() {
      TweetUi.getInstance();
      Log.i("ReactTwitterKit", "TweetUi instance initialized");
    }
  }).start();
}
 
Example #2
Source File: LoginActivity.java    From Simple-Blog-App with MIT License 6 votes vote down vote up
private void twitter() {
    TwitterConfig config = new TwitterConfig.Builder(this)
            .logger(new DefaultLogger(Log.DEBUG))
            .twitterAuthConfig(new TwitterAuthConfig(getResources().getString(R.string.com_twitter_sdk_android_CONSUMER_KEY), getResources().getString(R.string.com_twitter_sdk_android_CONSUMER_SECRET)))
            .debug(true)
            .build();
    Twitter.initialize(config);
    twitterLoginButton.setCallback(new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) {
            Log.d(TAG, "twitterLogin:success" + result);
            handleTwitterSession(result.data);
        }

        @Override
        public void failure(TwitterException exception) {
            Log.w(TAG, "twitterLogin:failure", exception);

        }
    });
}
 
Example #3
Source File: TweetUiTestCase.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    createMocks();

    // Initialize Fabric with mock executor so that kit#doInBackground() will not be called
    // during kit initialization.
    final TwitterConfig config = new TwitterConfig.Builder(getContext())
            .logger(new DefaultLogger(Log.DEBUG))
            .executorService(mock(ThreadPoolExecutor.class))
            .build();

    Twitter.initialize(config);

    final TwitterCore twitterCore = TwitterCoreTestUtils.createTwitterCore(
            new TwitterAuthConfig("", ""), clients, apiClient);

    tweetUi = TweetUi.getInstance();
    final TweetRepository tweetRepository = new TweetRepository(mainHandler,
            mock(SessionManager.class), twitterCore);
    tweetUi.setTweetRepository(tweetRepository);
    tweetUi.setImageLoader(picasso);
}
 
Example #4
Source File: AuthStateTest.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testBeginAuthorize_authHandlerCompareAndSetFails() {
    final AuthState authState = new AuthState();
    final boolean result = authState.beginAuthorize(mockActivity,
            new AuthHandler(mock(TwitterAuthConfig.class), mock(Callback.class),
                    TwitterAuthConfig.DEFAULT_AUTH_REQUEST_CODE) {
                @Override
                public boolean authorize(Activity activity) {
                    // We use this opportunity to set authState's authHandlerRef so that we
                    // can verify behavior when compare and set fails. This is done because
                    // AtomicReference has methods that cannot be mocked.
                    authState.authHandlerRef.set(mock(AuthHandler.class));
                    return true;
                }
            });
    assertFalse(result);
}
 
Example #5
Source File: OAuth2Service.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
private String getAuthHeader() {
    final TwitterAuthConfig authConfig = getTwitterCore().getAuthConfig();
    final ByteString string = ByteString.encodeUtf8(
            UrlUtils.percentEncode(authConfig.getConsumerKey())
            + ":"
            + UrlUtils.percentEncode(authConfig.getConsumerSecret()));

    return OAuthConstants.AUTHORIZATION_BASIC + " " + string.base64();
}
 
Example #6
Source File: OAuth1aService.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a callback url that is used to receive a request containing the oauth_token and
 * oauth_verifier parameters.
 *
 * @param authConfig The auth config
 * @return the callback url
 */
public String buildCallbackUrl(TwitterAuthConfig authConfig) {
    return Uri.parse(CALLBACK_URL).buildUpon()
            .appendQueryParameter("version", getTwitterCore().getVersion())
            .appendQueryParameter("app", authConfig.getConsumerKey())
            .build()
            .toString();
}
 
Example #7
Source File: OAuth1aService.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
/**
 * Requests a temp token to start the Twitter sign-in flow.
 *
 * @param callback The callback interface to invoke when the request completes.
 */
public void requestTempToken(final Callback<OAuthResponse> callback) {
    final TwitterAuthConfig config = getTwitterCore().getAuthConfig();
    final String url = getTempTokenUrl();

    api.getTempToken(new OAuth1aHeaders().getAuthorizationHeader(config, null,
            buildCallbackUrl(config), "POST", url, null)).enqueue(getCallbackWrapper(callback));
}
 
Example #8
Source File: TwitterAuthClient.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
TwitterAuthClient(TwitterCore twitterCore, TwitterAuthConfig authConfig,
                  SessionManager<TwitterSession> sessionManager, AuthState authState) {
    this.twitterCore = twitterCore;
    this.authState = authState;
    this.authConfig = authConfig;
    this.sessionManager = sessionManager;
}
 
Example #9
Source File: OAuthController.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
OAuthController(ProgressBar spinner, WebView webView, TwitterAuthConfig authConfig,
        OAuth1aService oAuth1aService, Listener listener) {
    this.spinner = spinner;
    this.webView = webView;
    this.authConfig = authConfig;
    this.oAuth1aService = oAuth1aService;
    this.listener = listener;
}
 
Example #10
Source File: OAuth1aServiceTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    authConfig = new TwitterAuthConfig("key", "secret");
    twitterCore = mock(TwitterCore.class);
    when(twitterCore.getAuthConfig()).thenReturn(authConfig);
    twitterApi = new TwitterApi();
    service = new OAuth1aService(twitterCore, twitterApi);
}
 
Example #11
Source File: OAuth1aHeadersTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: OAuth1aHeadersTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: OkHttpClientHelperTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCustomOkHttpClient_userAuth() throws Exception {
    final Interceptor mockInterceptor = mock(Interceptor.class);
    final OkHttpClient customHttpClient = new OkHttpClient.Builder()
            .addInterceptor(mockInterceptor).build();

    final TwitterSession mockSession = mock(TwitterSession.class);
    final OkHttpClient guestAuthHttpClient = OkHttpClientHelper.getCustomOkHttpClient(
            customHttpClient,
            mockSession,
            new TwitterAuthConfig("", ""));

    final List<Interceptor> interceptors = guestAuthHttpClient.interceptors();
    assertTrue(interceptors.contains(mockInterceptor));
}
 
Example #14
Source File: OAuthControllerTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {


    mockSpinner = mock(ProgressBar.class);
    mockWebView = mock(WebView.class);
    mockWebSettings = mock(WebSettings.class);
    when(mockWebView.getSettings()).thenReturn(mockWebSettings);

    mockOAuth1aService = mock(OAuth1aService.class);
    mockListener = mock(OAuthController.Listener.class);
    controller = new OAuthController(mockSpinner, mockWebView, mock(TwitterAuthConfig.class),
            mockOAuth1aService, mockListener);
}
 
Example #15
Source File: TwitterAuthClientTest.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    mockContext = mock(Context.class);
    when(mockContext.getPackageName()).thenReturn(getClass().getPackage().toString());

    mockTwitterCore = mock(TwitterCore.class);
    mockAuthConfig = mock(TwitterAuthConfig.class);
    when(mockAuthConfig.getRequestCode()).thenReturn(TEST_REQUEST_CODE);
    mockSessionManager = mock(SessionManager.class);
    mockAuthState = mock(AuthState.class);
    mockCallback = mock(Callback.class);

    authClient = new TwitterAuthClient(mockTwitterCore, mockAuthConfig, mockSessionManager,
            mockAuthState);
}
 
Example #16
Source File: RNDigits.java    From react-native-digits with MIT License 5 votes vote down vote up
public RNDigits(ReactApplicationContext reactContext) {
  super(reactContext);
  mContext = reactContext;
  
  final TwitterAuthConfig authConfig = getTwitterConfig();
  
  final Fabric fabric = new Fabric.Builder(mContext)
    .kits(new Digits(), new TwitterCore(authConfig))
    .logger(new DefaultLogger(Log.DEBUG))
    .debuggable(true)
    .build();
  
  Fabric.with(fabric);
}
 
Example #17
Source File: RNDigits.java    From react-native-digits with MIT License 5 votes vote down vote up
@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: InitContentProvider.java    From white-label-event-app with Apache License 2.0 5 votes vote down vote up
private void initFabric() {
    // Only initialize Fabric if Twitter integration is fully configured
    TwitterConfig.init(context);
    TwitterConfig config = TwitterConfig.getInstance();
    if (config.isConfigured()) {
        logger.info("Event hashtag is " + config.getEventHashtag() + ".  Initializing Fabric.");
        TwitterAuthConfig auth = new TwitterAuthConfig(config.getApiKey(), config.getApiSecret());
        Fabric.with(context, new Twitter(auth));
    }
    else {
        logger.info("Twitter integration is not configured; Fabric not initialized");
    }
}
 
Example #19
Source File: App.java    From twittererer with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    JodaTimeAndroid.init(this);

    Fabric.with(this, new Crashlytics());
    Twitter.initialize(new TwitterConfig.Builder(this).twitterAuthConfig(new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET)).build());

    applicationComponent = DaggerApp_ApplicationComponent.builder()
            .applicationModule(new ApplicationModule(this))
            .build();
}
 
Example #20
Source File: App.java    From cannonball-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    singleton = this;
    extractAvenir();
    authConfig
            = new TwitterAuthConfig(BuildConfig.CONSUMER_KEY, BuildConfig.CONSUMER_SECRET);
    Fabric.with(this, new Crashlytics(), new Digits(), new Twitter(authConfig), new MoPub());

    Crashlytics.setBool(CRASHLYTICS_KEY_CRASHES, areCrashesEnabled());
}
 
Example #21
Source File: TwitterLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
public TwitterLoginInstance(Activity activity, final LoginListener listener,
                            final boolean fetchUserInfo) {
    super(activity, listener, fetchUserInfo);

    TwitterConfig config = new TwitterConfig.Builder(activity)
            .logger(new DefaultLogger(Log.DEBUG))
            .twitterAuthConfig(new TwitterAuthConfig(ShareManager.CONFIG.getTwitterConsumerKey(),
                    ShareManager.CONFIG.getTwitterConsumerSecret()))
            .debug(BuildConfig.DEBUG).build();

    Twitter.initialize(config);
    mTwitterAuthClient = new TwitterAuthClient();
}
 
Example #22
Source File: AppLifecycleCallbacks.java    From photosearcher with Apache License 2.0 5 votes vote down vote up
/**
 * setup Twitter, Crashlytics
 */
protected void setupFabric() {
    TwitterAuthConfig authConfig = new TwitterAuthConfig(
            BuildConfig.TWITTER_API_KEY,
            BuildConfig.TWITTER_API_SECRET);
    Fabric.with(mApp, new Twitter(authConfig), new Crashlytics());
}
 
Example #23
Source File: App.java    From PracticeDemo with Apache License 2.0 5 votes vote down vote up
@Override
    public void onCreate() {
        super.onCreate();
        TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
//        Fabric.with(this, new TwitterCore(authConfig), new Digits());
        Fabric.with(this, new TwitterCore(authConfig),new TweetComposer());
    }
 
Example #24
Source File: OAuth1aHeaders.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
/**
 * @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 #25
Source File: OkHttpClientHelper.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
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 #26
Source File: OkHttpClientHelper.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
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 #27
Source File: OkHttpClientHelper.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
static OkHttpClient.Builder addSessionAuth(OkHttpClient.Builder builder,
                                           Session<? extends TwitterAuthToken> session,
                                           TwitterAuthConfig authConfig) {
    return builder
            .certificatePinner(getCertificatePinner())
            .addInterceptor(new OAuth1aInterceptor(session, authConfig));
}
 
Example #28
Source File: TwitterNetwork.java    From EasyLogin with MIT License 5 votes vote down vote up
public TwitterNetwork(Activity activity, String consumerKey, String consumerSecret) {
    TwitterAuthConfig authConfig = new TwitterAuthConfig(consumerKey, consumerSecret);
    TwitterConfig config = new TwitterConfig.Builder(activity.getApplicationContext())
            .logger(new DefaultLogger(Log.DEBUG))
            .twitterAuthConfig(authConfig)
            .build();
    Twitter.initialize(config);
}
 
Example #29
Source File: OAuth1aParameters.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
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 #30
Source File: SocialMediaSignUp.java    From socialmediasignup with MIT License 5 votes vote down vote up
private void initTwitter(Context appContext) {
    String consumerKey = SocialMediaSignUpUtils.getMetaDataValue(appContext, appContext.getString(R.string.com_ahmedadel_socialmediasignup_twitterConsumerKey));
    String consumerSecret = SocialMediaSignUpUtils.getMetaDataValue(appContext, appContext.getString(R.string.com_ahmedadel_socialmediasignup_twitterConsumerSecret));

    if (consumerKey != null && consumerSecret != null) {
        TwitterConfig twitterConfig = new TwitterConfig.Builder(appContext)
                .twitterAuthConfig(new TwitterAuthConfig(consumerKey, consumerSecret))
                .build();
        Twitter.initialize(twitterConfig);
    }
}