skip to Main Content

I am working in Spring-boot and I wanted to know if it is possible to authenticate the firebase cloud messaging by using basic auth instead of oauth

I want to use basic authentication with no tokens or anything like that

2

Answers


  1. No, it is not possible. You must follow the instructions in the documentation.

    The FCM HTTP v1 API authorizes requests with a short-lived OAuth 2.0 access token.

    Login or Signup to reply.
  2. FCM doesn’t support basic authentication, it requires the OAuth 2.0 tokens for authentication and authorization. For that,
    you can use Firebase Admin SDK, which will generate access tokens using service account credentials that you can use to authenticate with the FCM.

    An example code;

    FirebaseOptions options = new FirebaseOptions.Builder()
        .setCredentials(GoogleCredentials.fromStream(serviceAccount))
        .setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
        .build();
    
    FirebaseApp.initializeApp(options);
    
    String registrationToken = "<YOUR_DEVICE_REGISTRATION_TOKEN>";
    
    Message message = Message.builder()
        .putData("name", "John")
        .putData("surname", "Doe")
        .setToken(registrationToken)
        .build();
    
    String response = FirebaseMessaging.getInstance().send(message);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search