How to integrate firebase authentication with google app engine endpoints

前端 未结 2 1063
自闭症患者
自闭症患者 2021-01-31 00:07

I am writing a backend server for mobile applications. The backend is running on google app engine and written in Java.

I want users to be able to login with federated i

2条回答
  •  长发绾君心
    2021-01-31 00:32

    You should be able to use Google Cloud Endpoints as an authentication proxy in front of your app. Endpoints supports validating Firebase Authentication tokens by configuring your OpenAPI template:

    # Configure Firebase as an AuthN provider
    securityDefinitions:
        firebase:
          authorizationUrl: ""
          flow: "implicit"
          type: "oauth2"
          # Replace YOUR-PROJECT-ID with your project ID in the issuer and audiences fields
          x-google-issuer: "https://securetoken.google.com/YOUR-PROJECT-ID"
          x-google-audiences: "YOUR-PROJECT-ID"
          x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com"
    
    # Add Firebase as an authN provider to specific endpoints...
    security:
      - firebase: []
    

    Alternatively, you can use the Firebase Admin SDK to write authentication middleware that validates your tokens:

    FirebaseAuth.getInstance().verifyIdToken(idToken)
        .addOnSuccessListener(new OnSuccessListener() {
            @Override
            public void onSuccess(FirebaseToken decodedToken) {
                String uid = decodedToken.getUid();
                // ...
            }
    });
    

提交回复
热议问题