本文整理汇总了Java中com.google.firebase.auth.GetTokenResult类的典型用法代码示例。如果您正苦于以下问题:Java GetTokenResult类的具体用法?Java GetTokenResult怎么用?Java GetTokenResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GetTokenResult类属于com.google.firebase.auth包,在下文中一共展示了GetTokenResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIdToken
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
private void getIdToken(final boolean forceRefresh, final CallbackContext callbackContext) throws JSONException {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user == null) {
callbackContext.error("User is not authorized");
} else {
user.getIdToken(forceRefresh)
.addOnCompleteListener(cordova.getActivity(), new OnCompleteListener<GetTokenResult>() {
@Override
public void onComplete(Task<GetTokenResult> task) {
if (task.isSuccessful()) {
callbackContext.success(task.getResult().getToken());
} else {
callbackContext.error(task.getException().getMessage());
}
}
});
}
}
});
}
开发者ID:chemerisuk,项目名称:cordova-plugin-firebase-authentication,代码行数:25,代码来源:FirebaseAuthenticationPlugin.java
示例2: subscribe
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
@Override public void subscribe(final SingleEmitter<String> emitter) {
OnCompleteListener<GetTokenResult> listener = new OnCompleteListener<GetTokenResult>() {
@Override public void onComplete(@NonNull Task<GetTokenResult> task) {
if (!task.isSuccessful()) {
if (!emitter.isDisposed()) {
emitter.onError(task.getException());
}
return;
}
if (!emitter.isDisposed()) {
emitter.onSuccess(task.getResult().getToken());
}
}
};
user.getToken(forceRefresh).addOnCompleteListener(listener);
}
示例3: getTokenFirebase
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
public static String getTokenFirebase() {
final StringBuilder tokenAux = new StringBuilder();
final CountDownLatch countDownLatch = new CountDownLatch(1);
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
user.getToken(false).addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
@Override
public void onComplete(@NonNull Task<GetTokenResult> task) {
tokenAux.append(task.getResult().getToken());
countDownLatch.countDown();
}
});
try {
countDownLatch.await(30L, TimeUnit.SECONDS);
return tokenAux.toString();
} catch (InterruptedException ie) {
return null;
}
}
return null;
}
示例4: getToken
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
@Test
public void getToken() throws InterruptedException {
TestSubscriber<GetTokenResult> testSubscriber = new TestSubscriber<>();
RxFirebaseUser.getToken(mockUser, true)
.subscribeOn(Schedulers.immediate())
.subscribe(testSubscriber);
testOnSuccessListener.getValue().onSuccess(tokenResult);
testOnCompleteListener.getValue().onComplete(mockTokenTask);
verify(mockUser).getToken(true);
testSubscriber.assertNoErrors();
testSubscriber.assertValueCount(1);
testSubscriber.assertReceivedOnNext(Collections.singletonList(tokenResult));
testSubscriber.assertCompleted();
testSubscriber.unsubscribe();
}
示例5: startLoadingProcess
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
public void startLoadingProcess(final Context context) {
AppPrefs prefs = new AppPrefs(context);
final FirebaseAuth auth = FirebaseAuth.getInstance();
if (auth.getCurrentUser() != null) {
auth.getCurrentUser().getIdToken(false).addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
@Override
public void onComplete(@NonNull Task<GetTokenResult> task) {
if (task.isSuccessful()) {
String user = auth.getCurrentUser().getUid();
String email = auth.getCurrentUser().getEmail();
checkIfOld(task.getResult().getToken(), user, context, email);
} else {
if (task.getException() != null) {
showError(task.getException().getLocalizedMessage());
} else {
showError("Unable to get user data! Please try again.");
}
}
}
});
} else {
showError("Something is wrong, please try logging again.");
}
}
示例6: getUserToken
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
public Observable<String> getUserToken(FirebaseUser firebaseUser) {
return Observable.create(subscriber -> {
Task<GetTokenResult> task = firebaseUser.getToken(true);
task.addOnCompleteListener(resultTask -> {
if (task.isSuccessful()) {
String token = task.getResult().getToken();
subscriber.onNext(token);
subscriber.onCompleted();
} else {
Exception e = task.getException();
subscriber.onError(e);
}
});
});
}
示例7: getToken
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
/**
* @param user
* @param forceRefresh
* @return
*/
@CheckReturnValue
@NonNull
public static Single<String> getToken(@NonNull final FirebaseUser user,
final boolean forceRefresh) {
return RxTask.single(new Callable<Task<GetTokenResult>>() {
@Override
public Task<GetTokenResult> call() throws Exception {
return user.getToken(forceRefresh);
}
})
.map(new Function<GetTokenResult, String>() {
@Override
public String apply(@NonNull GetTokenResult getTokenResult) throws Exception {
return getTokenResult.getToken();
}
});
}
示例8: getIdTokenForCurrentUser
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
public static void getIdTokenForCurrentUser(final RequestFirebaseIdTokenCallback callback) {
if (getCurrentFirebaseUser() == null) {
Log.v(TAG, "Getting Token error. ERROR = Current Firebse User is null");
SharedHelper.getInstance().saveFirebaseToken(null);
callback.onError(new NullPointerException("Current Firebse User is null"));
return;
}
getCurrentFirebaseUser().getIdToken(false).addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
public void onComplete(@NonNull Task<GetTokenResult> task) {
if (task.isSuccessful()) {
String accessToken = task.getResult().getToken();
Log.v(TAG, "Token got successfully. TOKEN = " + accessToken);
SharedHelper.getInstance().saveFirebaseToken(accessToken);
callback.onSuccess(accessToken);
} else {
Log.v(TAG, "Getting Token error. ERROR = " + task.getException().getMessage());
callback.onError(task.getException());
}
}
});
}
示例9: getToken
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
/**
* Fetches a Firebase Auth ID Token for the user; useful when authenticating against your own backend.
*
* @param firebaseUser current firebaseUser instance.
* @param forceRefresh force to refresh the token ID.
* @return a {@link Maybe} which emits an {@link GetTokenResult} if success.
*/
@NonNull
public static Maybe<GetTokenResult> getToken(@NonNull final FirebaseUser firebaseUser,
final boolean forceRefresh) {
return Maybe.create(new MaybeOnSubscribe<GetTokenResult>() {
@Override
public void subscribe(MaybeEmitter<GetTokenResult> emitter) throws Exception {
RxHandler.assignOnTask(emitter, firebaseUser.getToken(forceRefresh));
}
});
}
示例10: getToken
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
@NonNull
public static Observable<GetTokenResult> getToken(@NonNull final FirebaseUser firebaseUser,
final boolean forceRefresh) {
return Observable.create(new Observable.OnSubscribe<GetTokenResult>() {
@Override
public void call(final Subscriber<? super GetTokenResult> subscriber) {
RxHandler.assignOnTask(subscriber, firebaseUser.getToken(forceRefresh));
}
});
}
示例11: updateUI
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
private void updateUI(FirebaseUser user) {
hideProgressDialog();
if (user != null) {
mStatusTextView.setText(getString(R.string.google_status_fmt, user.getEmail()));
mDetailTextView.setText(getString(R.string.firebase_status_fmt, user.getUid()));
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE);
user.getToken(true).addOnSuccessListener(new OnSuccessListener<GetTokenResult>() {
@Override
public void onSuccess(GetTokenResult getTokenResult) {
makeEndpointsRequest(getTokenResult.getToken());
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
alert("Failed to get token from Firebase.");
}
});
} else {
mStatusTextView.setText(R.string.signed_out);
mDetailTextView.setText(null);
mResponseTextView.setText("");
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE);
}
}
示例12: updateUI
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
private void updateUI(FirebaseUser user) {
hideProgressDialog();
if (user != null) {
mStatusTextView.setText(getString(R.string.facebook_status_fmt, user.getDisplayName()));
mDetailTextView.setText(getString(R.string.firebase_status_fmt, user.getUid()));
findViewById(R.id.button_facebook_login).setVisibility(View.GONE);
findViewById(R.id.button_facebook_signout).setVisibility(View.VISIBLE);
user.getToken(true).addOnSuccessListener(new OnSuccessListener<GetTokenResult>() {
@Override
public void onSuccess(GetTokenResult getTokenResult) {
makeEndpointsRequest(getTokenResult.getToken());
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
alert("Failed to get token from Firebase.");
}
});
} else {
mStatusTextView.setText(R.string.signed_out);
mDetailTextView.setText(null);
mResponseTextView.setText("");
findViewById(R.id.button_facebook_login).setVisibility(View.VISIBLE);
findViewById(R.id.button_facebook_signout).setVisibility(View.GONE);
}
}
示例13: loadAuthToken
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
/**
* Load the user's auth token if it is available.
*/
private void loadAuthToken() {
final FirebaseUser auth = FirebaseAuth.getInstance().getCurrentUser();
if(auth != null) {
try {
final GetTokenResult result = Tasks.await(auth.getIdToken(true));
mAuthToken = result.getToken();
} catch(ExecutionException | InterruptedException e) {
Log.e(TAG, "Failed to obtain authorization token", e);
}
}
}
示例14: getToken
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
@ReactMethod
public void getToken(final Callback callback) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
user.getToken(true)
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
@Override
public void onComplete(@NonNull Task<GetTokenResult> task) {
if (task.isSuccessful()) {
String token = task.getResult().getToken();
WritableMap resp = Arguments.createMap();
resp.putString("status", "complete");
resp.putString("token", token);
callback.invoke(null, resp);
} else {
WritableMap err = Arguments.createMap();
err.putInt("errorCode", ERROR_FETCHING_TOKEN);
err.putString("errorMessage", task.getException().getMessage());
callback.invoke(err);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
示例15: userCallback
import com.google.firebase.auth.GetTokenResult; //导入依赖的package包/类
public void userCallback(FirebaseUser passedUser, final Callback callback) {
if (passedUser == null) {
mAuth = FirebaseAuth.getInstance();
this.user = mAuth.getCurrentUser();
} else {
this.user = passedUser;
}
this.user.getToken(false).addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
@Override
public void onComplete(@NonNull Task<GetTokenResult> task) {
WritableMap msgMap = Arguments.createMap();
WritableMap userMap = getUserMap();
boolean authenticated = false;
if (FirestackAuthModule.this.user != null) {
final String token = task.getResult().getToken();
userMap.putString("token", token);
authenticated = true;
}
msgMap.putMap("user", userMap);
msgMap.putBoolean("authenticated", authenticated);
callback.invoke(null, msgMap);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception ex) {
userExceptionCallback(ex, callback);
}
});
}