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

Expose the jwt-token method #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/fcm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ def send_to_topic_condition(condition, options = {})
end
end

def jwt_token
scope = "https://www.googleapis.com/auth/firebase.messaging"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

@authorizer ||= Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: json_key,
scope: scope,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/TrailingCommaInArguments: Avoid comma after the last parameter of a method call.

)
token = @authorizer.fetch_access_token!
token["access_token"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

end

private

def for_uri(uri, extra_headers = {})
Expand Down Expand Up @@ -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
Expand Down