Skip to content

Commit

Permalink
Merge pull request #43 from miyataka/feat/server_key_deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
miyataka authored Jan 15, 2024
2 parents 872a528 + 7279394 commit 2731106
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ Fcmpush.configure do |config|

## for topic subscribe/unsubscribe because they use regacy auth
# firebase web console => project settings => cloud messaging => Project credentials => Server key
# @deprecated: This attribute will be removed next version.
config.server_key = 'your firebase server key'
# Or set environment variables
# @deprecated: This attribute will be removed next version.
# ENV['FCM_SERVER_KEY'] = 'your firebase server key'

# Proxy ENV variables are considered by default if set by net/http, but you can explicitly define your proxy host here
Expand Down
9 changes: 7 additions & 2 deletions lib/fcmpush/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(domain, project_id, configuration, **options)
access_token_response = v1_authorize
@access_token = access_token_response['access_token']
@access_token_expiry = Time.now.utc + access_token_response['expires_in']
@server_key = configuration.server_key
# @server_key = configuration.server_key
@connection = Net::HTTP::Persistent.new

if !configuration.proxy
Expand Down Expand Up @@ -112,7 +112,10 @@ def make_subscription_request(topic, instance_ids, type, query, headers)
uri = URI.join(TOPIC_DOMAIN, TOPIC_ENDPOINT_PREFIX + suffix)
uri.query = URI.encode_www_form(query) unless query.empty?

headers = legacy_authorized_header(headers)
headers = v1_authorized_header(headers)
# cf. https://takanamito.hateblo.jp/entry/2020/07/04/175045
# cf. https://github.com/miyataka/fcmpush/issues/40
headers['access_token_auth'] = 'true'
post = Net::HTTP::Post.new(uri, headers)
post.body = make_subscription_body(topic, *instance_ids)

Expand All @@ -133,7 +136,9 @@ def v1_authorized_header(headers)
'Authorization' => "Bearer #{access_token}")
end

# @deprecated TODO: remove this method next version
def legacy_authorized_header(headers)
warn "[DEPRECATION] `legacy_authorized_header` is deprecated. Please use `v1_authorized_header` instead."
headers.merge('Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => "Bearer #{server_key}")
Expand Down
4 changes: 4 additions & 0 deletions lib/fcmpush/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def initialize
# ENV['GOOGLE_PRIVATE_KEY'] = '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n'

# regacy auth
# @deprecated TODO: remove this next version
@server_key = ENV['FCM_SERVER_KEY']
if @server_key
warn '[DEPRECATION] `FCM_SERVER_KEY` environment variable, also @server_key is deprecated. This attribute will be removed next version.'
end

# THIS IS EXPERIMENTAL
# NOT support `HTTPS_PROXY` environment variable. This feature not tested well on CI.
Expand Down

0 comments on commit 2731106

Please sign in to comment.