最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Empty refresh token using facebook auth in kotlin - Stack Overflow

programmeradmin4浏览0评论

I am trying to set up facebook auth for my application using supabase database and kotlin.

I get the access token from Facebook auth, but when try to save current session using using refresh token i have a problem because the refresh token is empty.

here is current session: session: UserSession(accessToken=EAAaEv....., refreshToken=, providerRefreshToken=, providerToken=, expiresIn=0, tokenType=, user=null, type=, expiresAt=2025-03-16T21:56:09.227762Z)

 fun signInWithFacebook(
    context: Context, accessToken: String
): CompletableFuture<Unit> {
    return GlobalScope.future {
        try {
            supabase.auth.signInWith(Facebook)
            supabase.auth.importAuthToken(accessToken)
            val session = supabase.auth.currentSessionOrNull();
            val refreshToken = session?.refreshToken
            println("refreshToken $refreshToken")
            println("session $session")
            
            saveRefreshToken(context, refreshToken)
        } catch (e: Exception) {
            println("Exception ${e}")
            throw e
        }
    }
}

logInWithFacebookMethod in the activity:

public void logInWithFacebook(View view) {
    CallbackManager callbackManager = CallbackManager.Factory.create();
    LoginButton facebookLoginButton = findViewById(R.id.facebook);
    facebookLoginButton.setPermissions("email", "public_profile");
    facebookLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            if (loginResult != null) {
                String accessToken = loginResult.getAccessToken().getToken();
                GraphRequest graphRequest = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                        if (jsonObject != null) {
                            try {
                                String username = jsonObject.getString("name");
                                String email = jsonObject.getString("email");
                                SupabaseClient.INSTANCE.signInWithFacebook(SignUpActivity.this, accessToken).whenComplete((response, error) -> {
                                   //handle response
                                });
                            } catch (JSONException e) {
                                throw new RuntimeException(e);
                            }
                        }
                    }
                });
                Bundle bundle = new Bundle();
                bundle.putString("fields", "name, email");
                graphRequest.setParameters(bundle);
                graphRequest.executeAsync();
            }
        }

        @Override
        public void onCancel() {
        }

        @Override
        public void onError(@NonNull FacebookException error) {
        }
    });

    facebookLoginButton.performClick();
}
发布评论

评论列表(0)

  1. 暂无评论