Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

depricated authorization for topic management #122

Closed
aap17 opened this issue Aug 31, 2024 · 4 comments
Closed

depricated authorization for topic management #122

aap17 opened this issue Aug 31, 2024 · 4 comments

Comments

@aap17
Copy link

aap17 commented Aug 31, 2024

it seems the latest library version works with legacy API for requests with topic

  def topic_subscription(topic, registration_id)
    for_uri(INSTANCE_ID_API) do |connection|
      response = connection.post("/iid/v1/#{registration_id}/rel/topics/#{topic}")
      build_response(response)
    end
  end


...

  connection = ::Faraday.new(
      url: uri,
      request: { timeout: DEFAULT_TIMEOUT }
    ) do |faraday|
      faraday.adapter Faraday.default_adapter
      faraday.headers["Content-Type"] = "application/json"
      faraday.headers['Authorization'] = "key=#{@api_key}"
      extra_headers.each do |key, value|
        faraday.headers[key] = value
      end
    end

No Bearer token inside connection, the request fails with error "Authentication using server key is depricated..."

But push messages works perfect with direct sending, it was fixed with V1 Bearer auth type:

  def send_notification_v1(message)
    return if @project_name.empty?

    post_body = { 'message': message }
    extra_headers = {
      'Authorization' => "Bearer #{jwt_token}"
    }
    for_uri(BASE_URI_V1, extra_headers) do |connection|
      response = connection.post(
        "#{@project_name}/messages:send", post_body.to_json
      )
      build_response(response)
    end
  end
@nuzelac
Copy link

nuzelac commented Sep 1, 2024

I had to also add access_token_auth header for topic subscription.

From https://developers.google.com/instance-id/reference/server#create_relationship_maps_for_app_instances

https://iid.googleapis.com/iid/v1/nKctODamlM4:CKrh_PC8kIb7O...clJONHoA/rel/topics/movies
Content-Type:application/json
Content-Length: 0
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
access_token_auth: true

@aap17
Copy link
Author

aap17 commented Sep 2, 2024

I have fixed it in my fork.
https://github.com/aap17/fcm_v1

I would be happy if someone will update it here

@robink
Copy link

robink commented Sep 3, 2024

Also migrated send_to_topic_condition
aap17#1

@sabman
Copy link
Member

sabman commented Sep 18, 2024

#123 (comment)

@sabman sabman closed this as completed Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants