本文整理汇总了Java中com.google.firebase.auth.TwitterAuthProvider类的典型用法代码示例。如果您正苦于以下问题:Java TwitterAuthProvider类的具体用法?Java TwitterAuthProvider怎么用?Java TwitterAuthProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TwitterAuthProvider类属于com.google.firebase.auth包,在下文中一共展示了TwitterAuthProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleTwitterSession
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
private void handleTwitterSession(TwitterSession session) {
Log.d(TAG, "handleTwitterSession:" + session);
AuthCredential credential = TwitterAuthProvider.getCredential(
session.getAuthToken().token,
session.getAuthToken().secret);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(MainActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// ...
}
});
}
示例2: handleTwitterSession
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
private void handleTwitterSession(TwitterSession session) {
Utils.d("Twitter:HandleSession:" + session);
AuthCredential credential = TwitterAuthProvider.getCredential(
session.getAuthToken().token,
session.getAuthToken().secret);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Utils.d("signInWithCredential:success");
} else {
// If sign in fails, display a message to the user.
Utils.w("signInWithCredential:failure: " + task.getException());
}
// ...
}
});
}
示例3: getCredential
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
public static AuthCredential getCredential(final JSONObject credential) throws Exception {
final String providerId = credential.getString("provider");
AuthCredential authCredential;
if (providerId.equals(EmailAuthProvider.PROVIDER_ID)) {
authCredential = getEmailAuthCredential(credential);
} else if (providerId.equals(FacebookAuthProvider.PROVIDER_ID)) {
authCredential = getFacebookAuthCredential(credential);
} else if (providerId.equals(GithubAuthProvider.PROVIDER_ID)) {
authCredential = getGithubAuthCredential(credential);
} else if (providerId.equals(GoogleAuthProvider.PROVIDER_ID)) {
authCredential = getGoogleAuthCredential(credential);
} else if (providerId.equals(TwitterAuthProvider.PROVIDER_ID)) {
authCredential = getTwitterAuthCredential(credential);
} else {
throw new Exception("Unknown provider ID: " + providerId);
}
return authCredential;
}
示例4: doInBackground
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... voids) {
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user != null) {
for(UserInfo info : user.getProviderData()) {
switch(info.getProviderId()) {
case GoogleAuthProvider.PROVIDER_ID:
logoutGoogle();
break;
case FacebookAuthProvider.PROVIDER_ID:
logoutFacebook();
break;
case TwitterAuthProvider.PROVIDER_ID:
logoutTwitter();
break;
}
}
FirebaseAuth.getInstance().signOut();
}
return null;
}
示例5: twitterLogin
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
@ReactMethod
public void twitterLogin(String Token, String Secret, final Callback callback) {
mAuth = FirebaseAuth.getInstance();
AuthCredential credential = TwitterAuthProvider.getCredential(Token, Secret);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirestackAuthModule.this.user = task.getResult().getUser();
userCallback(FirestackAuthModule.this.user, callback);
}else{
// userErrorCallback(task, callback);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
示例6: handleTwitterSession
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
void handleTwitterSession(TwitterSession session) {
Timber.d("handleTwitterSession:" + session);
AuthCredential credential = TwitterAuthProvider.getCredential(
session.getAuthToken().token,
session.getAuthToken().secret);
mAuth.signInWithCredential(credential)
.addOnCompleteListener((Activity) mContext, task -> {
Timber.d("signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Timber.w("signInWithTwitterCredential", task.getException());
mEventBus.post(new LoginEvent(false, "Twitter Auth Failed : " + task.getException().getMessage()));
} else {
Timber.w("signInWithTwitterCredential", "success with email " + task.getResult().getUser().getEmail());
mEventBus.post(new LoginEvent(true, "Twitter Auth Success"));
}
});
}
示例7: build
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
public IdpResponse build() {
String providerId = mUser.getProviderId();
if (!AuthUI.SUPPORTED_PROVIDERS.contains(providerId)) {
throw new IllegalStateException("Unknown provider: " + providerId);
}
if (AuthUI.SOCIAL_PROVIDERS.contains(providerId) && TextUtils.isEmpty(mToken)) {
throw new IllegalStateException(
"Token cannot be null when using a non-email provider.");
}
if (providerId.equals(TwitterAuthProvider.PROVIDER_ID)
&& TextUtils.isEmpty(mSecret)) {
throw new IllegalStateException(
"Secret cannot be null when using the Twitter provider.");
}
return new IdpResponse(mUser, mToken, mSecret);
}
示例8: providerIdToAccountType
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
/**
* Translate a Firebase Auth provider ID (such as {@link GoogleAuthProvider#PROVIDER_ID}) to a
* Credentials API account type (such as {@link IdentityProviders#GOOGLE}).
*/
public static String providerIdToAccountType(@AuthUI.SupportedProvider @NonNull String providerId) {
switch (providerId) {
case GoogleAuthProvider.PROVIDER_ID:
return IdentityProviders.GOOGLE;
case FacebookAuthProvider.PROVIDER_ID:
return IdentityProviders.FACEBOOK;
case TwitterAuthProvider.PROVIDER_ID:
return IdentityProviders.TWITTER;
case PhoneAuthProvider.PROVIDER_ID:
return PHONE_IDENTITY;
// The account type for email/password creds is null
case EmailAuthProvider.PROVIDER_ID:
default:
return null;
}
}
示例9: testTwitterLoginFlowStarts
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
@Test
@Config(shadows = {AuthHelperShadow.class})
public void testTwitterLoginFlowStarts() {
List<String> providers = Arrays.asList(AuthUI.TWITTER_PROVIDER);
AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);
when(AuthHelperShadow.getCurrentUser().getProviders())
.thenReturn(Arrays.asList(TwitterAuthProvider.PROVIDER_ID));
when(AuthHelperShadow.getFirebaseAuth().signInWithCredential(any(AuthCredential.class)))
.thenReturn(new AutoCompleteTask<>(FakeAuthResult.INSTANCE, true, null));
Button twitterButton =
authMethodPickerActivity.findViewById(R.id.twitter_button);
assertNotNull(twitterButton);
twitterButton.performClick();
ShadowActivity.IntentForResult nextIntent =
Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult();
assertTrue(nextIntent.intent.getComponent().getClassName().contains("com.twitter.sdk"));
}
示例10: handleTwitterSession
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
private void handleTwitterSession(TwitterSession session) {
AuthCredential credential = TwitterAuthProvider.getCredential(session.getAuthToken().token, session.getAuthToken().secret);
if (mAuth.getCurrentUser() == null) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(LoginActivity.this, new LoginCallback(LoginActivity.this, false, "connect_to_twitter"));
} else {
mAuth.getCurrentUser()
.linkWithCredential(credential)
.addOnCompleteListener(LoginActivity.this, new LoginCallback(LoginActivity.this, true, "connect_to_twitter"));
}
}
示例11: handleTwitterSession
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
private void handleTwitterSession(TwitterSession session) {
AuthCredential credential = TwitterAuthProvider.getCredential(session.getAuthToken().token, session.getAuthToken().secret);
if (mAuth.getCurrentUser() == null) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new LoginCallback(this, false, "connect_to_twitter"));
} else {
mAuth.getCurrentUser()
.linkWithCredential(credential)
.addOnCompleteListener(this, new LoginCallback(this, true, "connect_to_twitter"));
}
}
示例12: handleTwitterSession
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
private void handleTwitterSession(TwitterSession session) {
Log.d(TAG, "handleTwitterSession:" + session);
// [START_EXCLUDE silent]
showProgressDialog();
// [END_EXCLUDE]
AuthCredential credential = TwitterAuthProvider.getCredential(
session.getAuthToken().token,
session.getAuthToken().secret);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success");
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.getException());
Toast.makeText(TwitterLoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
updateUI(null);
}
// [START_EXCLUDE]
hideProgressDialog();
// [END_EXCLUDE]
}
});
}
示例13: handleTwitterSession
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
private void handleTwitterSession(TwitterSession session) {
Log.d(TAG, "handleTwitterSession:" + session);
// [START_EXCLUDE silent]
showProgressDialog();
// [END_EXCLUDE]
AuthCredential credential = TwitterAuthProvider.getCredential(
session.getAuthToken().token,
session.getAuthToken().secret);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(TwitterLoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// [START_EXCLUDE]
hideProgressDialog();
// [END_EXCLUDE]
}
});
}
示例14: signInTwitter
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
private void signInTwitter(String token, String secret) {
AuthCredential credential = TwitterAuthProvider.getCredential(token, secret);
firebaseAuth.signInWithCredential(credential).addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d("TAG", "signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w("TAG", "signInWithCredential", task.getException());
Toast.makeText(getActivity(), "Authentication failed.",
Toast.LENGTH_SHORT).show();
getActivity().finish();
} else {
user = task.getResult().getUser();
registerUserInDatabase();
if (listener != null) {
Bundle bundle = new Bundle();
listener.onFragmentInteraction(Constants.SIGN_UP_FRAGMENT, bundle);
} else {
getActivity().finish();
}
}
}
});
}
示例15: firebaseAuthWithTwitter
import com.google.firebase.auth.TwitterAuthProvider; //导入依赖的package包/类
/**
* Authenticate with Firebase using a Twitter token.
*
* @param session The TwitterSession
*/
private void firebaseAuthWithTwitter(@NonNull TwitterSession session) {
final AuthCredential credential = TwitterAuthProvider.getCredential(
session.getAuthToken().token,
session.getAuthToken().secret);
mAuth.signInWithCredential(credential);
}