Git Product home page Git Product logo

Comments (3)

miyataka avatar miyataka commented on June 8, 2024 3

NOW, server_key is deprecated on v1.4.3!!

Thank you all!!
@lackneets @ryy

from fcmpush.

ryy avatar ryy commented on June 8, 2024 2

I have faced this problem before.
I tried to use access_token instead of server_key but it didn't work.

def legacy_authorized_header(headers)
headers.merge('Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => "Bearer #{server_key}")
end

def legacy_authorized_header(headers)
  headers.merge('Content-Type' => 'application/json',
                'Accept' => 'application/json',
-                'Authorization' => "Bearer #{server_key}"
+                'Authorization' => "Bearer #{access_token}")
end
Fcmpush::Unauthorized: Received 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>

However, I found a way to make subscribe and unsubscribe work with access_token.

Could you please assign this issue to me?

from fcmpush.

ryy avatar ryy commented on June 8, 2024 2

Sorry, I'm not sure how to do this. I did not describe the solution.

Add the following to the header

access_token_auth: true.

ref: https://takanamito.hateblo.jp/entry/2020/07/04/175045

It works.

# config/initializers/monkey_patches.rb

Dir[Rails.root.join('lib', 'monkey_patches', '**', '*.rb')].each do |file|
    require file
end
# lib/monkey_patches/fcmpush/client.rb

module FcmPushMonkeyPatch
    module Client
      private
  
      def legacy_authorized_header(headers)
        headers.merge('Content-Type' => 'application/json',
                      'Accept' => 'application/json',
                      'Authorization' => "Bearer #{access_token}", # <- Change from server_key to access_token
                      'access_token_auth' => 'true') # <- add new header key value
      end
    end
end
  
Fcmpush::Client.prepend(FcmPushMonkeyPatch::Client)

from fcmpush.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.