From dc3294148dd4f650725156d852c3fb72d1416f11 Mon Sep 17 00:00:00 2001 From: Josh Hollinshead Date: Wed, 27 Sep 2023 13:40:40 +1300 Subject: [PATCH] Expose the jwt-token method, so that its easy for consumers of the FCM gem to make custom requests directly to the firebase http API's if/when required --- lib/fcm.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/fcm.rb b/lib/fcm.rb index 08980ce..eead637 100644 --- a/lib/fcm.rb +++ b/lib/fcm.rb @@ -217,6 +217,16 @@ def send_to_topic_condition(condition, options = {}) end end + def jwt_token + scope = "https://www.googleapis.com/auth/firebase.messaging" + @authorizer ||= Google::Auth::ServiceAccountCredentials.make_creds( + json_key_io: json_key, + scope: scope, + ) + token = @authorizer.fetch_access_token! + token["access_token"] + end + private def for_uri(uri, extra_headers = {}) @@ -316,16 +326,6 @@ def validate_condition_topics?(condition) topics.all? { |topic| topic.gsub(TOPIC_REGEX, "").length == 0 } end - def jwt_token - scope = "https://www.googleapis.com/auth/firebase.messaging" - @authorizer ||= Google::Auth::ServiceAccountCredentials.make_creds( - json_key_io: json_key, - scope: scope, - ) - token = @authorizer.fetch_access_token! - token["access_token"] - end - def json_key @json_key ||= if @json_key_path.respond_to?(:read) @json_key_path