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

fix: subscribe and unsubscribe methods not working #36

Merged
merged 1 commit into from
Jul 2, 2023

Conversation

ryy
Copy link
Contributor

@ryy ryy commented Jun 30, 2023

Hi, there.

subscribe and unsubscribe methods haven't worked since last week.

They return a 404 401 status.

failed rspec.

1) Fcmpush Fcmpush::Client #subscribe subscribe test
    Failure/Error: raise error.new("Receieved an error response #{response.code} #{error.to_s.split('::').last}: #{response.body}", response) if error
    
    Fcmpush::Unauthorized:
    Receieved an error response 401 Unauthorized: <HTML>
    <HEAD>
    <TITLE>Unauthorized</TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
    <H1>Unauthorized</H1>
    <H2>Error 401</H2>
    </BODY>
    </HTML>
    # ./lib/fcmpush/client.rb:132:in `exception_handler'
    # ./lib/fcmpush/client.rb:60:in `subscribe'
    # ./spec/fcmpush_spec.rb:60:in `block (4 levels) in <top (required)>'

Finished in 6.5 seconds (files took 0.67857 seconds to load)
1 example, 1 failure

Perhaps, it doesn't work if there is a key= in the Authentication to be included in the headers.
Removing this made it work.

refs:
https://firebase.google.com/support/faq?hl=en#fcm-depr-features
https://firebase.google.com/docs/cloud-messaging/migrate-v1?hl=en#after-send-auth

@ryy ryy changed the title fix: subscribe and unsubscribe methods not working. fix: subscribe and unsubscribe methods not working Jun 30, 2023
@miyataka
Copy link
Owner

@ryy
Thank you for your contribution!!

Instead of modifying and using legacy_authorized_header, I believe it would be preferable to use v1_authorized_header. Would you be willing to give it a try? The reason is that the legacy version uses the server key, while the v1 version use an access token.

(translated by chatGPT)


legacy_authorized_header を修正して使うよりも、v1_authorized_header を使う方が良いと思います。試してみてもらえないでしょうか?
legacyのほうは、server keyを使っているのに対して、v1のほうはaccess_tokenを使っているので。

@ryy
Copy link
Contributor Author

ryy commented Jun 30, 2023

Thank you for your response!
I tried it.


つまり、subscriptionのリクエスト時のヘッダーの設定を変更するということですね?

headers = legacy_authorized_header(headers)

- headers = legacy_authorized_header(headers)
+ headers = v1_authorized_header(headers)

同じく401が返ってきます

config.server_keyの設定およびconfiguration.json_key_ioにはfirebaseのサービスアカウント(json)を正しくセットできています。

  1) Fcmpush Fcmpush::Client #subscribe subscribe test
     Failure/Error: raise error.new("Receieved an error response #{response.code} #{error.to_s.split('::').last}: #{response.body}", response) if error
     
     Fcmpush::Unauthorized:
       Receieved an error response 401 Unauthorized: <HTML>
       <HEAD>
       <TITLE>Unauthorized</TITLE>
       </HEAD>
       <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
       <H1>Unauthorized</H1>
       <H2>Error 401</H2>
       </BODY>
       </HTML>

@dlackty
Copy link

dlackty commented Jun 30, 2023

同じエラーに遭遇しましたが、このPRが問題を修正していることを確認できます。本当にありがとうございます。

@miyataka
Copy link
Owner

miyataka commented Jul 2, 2023

@ryy CC: @dlackty
遅くなりすみません.自分のローカルでも同様の結果が確認できたので,マージします.

Your patch completely worked!! My comment was wrong.
Thank you very much.

@miyataka miyataka merged commit 03085b6 into miyataka:main Jul 2, 2023
@miyataka
Copy link
Owner

miyataka commented Jul 2, 2023

And Released v1.4.1 !!
https://rubygems.org/gems/fcmpush

Thanks again. @ryy

@ryy ryy mentioned this pull request Jan 1, 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

Successfully merging this pull request may close these issues.

None yet

3 participants