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

Accept any IO object for credentials #94

Merged
merged 3 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion lib/fcm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,18 @@ def validate_condition_topics?(condition)
def jwt_token
scope = "https://www.googleapis.com/auth/firebase.messaging"
authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open(@json_key_path),
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
else
File.open(@json_key_path)
end
end
end
12 changes: 12 additions & 0 deletions spec/fcm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,16 @@
describe "subscribing to a topic" do
# TODO
end

describe "credentials path" do
excid3 marked this conversation as resolved.
Show resolved Hide resolved
it "can be a path to a file" do
excid3 marked this conversation as resolved.
Show resolved Hide resolved
fcm = FCM.new("test", "README.md")
excid3 marked this conversation as resolved.
Show resolved Hide resolved
expect(fcm.__send__(:json_key).class).to eq(File)
end

it "can be an IO object" do
excid3 marked this conversation as resolved.
Show resolved Hide resolved
fcm = FCM.new("test", StringIO.new("hey"))
excid3 marked this conversation as resolved.
Show resolved Hide resolved
expect(fcm.__send__(:json_key).class).to eq(StringIO)
end
end
end