Module JokenJwks.DefaultMatchStrategy is not loaded and could not be found

Hi
I am trying to decode idToken jwt strings from google gave using Joken and Joken_jwks

And I followed steps that dos says

lib/my_app/google_token.ex

defmodule MyApp.GoogleToken do
  use Joken.Config
  
  add_hook(JokenJwks, strategy: MyApp.MyStrategy)
end

lib/my_app/my_strategy.ex

defmodule MyApp.MyStrategy do
  use JokenJwks.DefaultStrategy
  
  def init_opts(opts) do
    url = "https://www.googleapis.com/oauth2/v3/certs"
    Keyword.merge(opts, jwks_url: url)
  end
end

lib/my_app/application.ex

def start(_type, _args) do
  children = [
   # other code
   {MyApp.MyStrategy, time_interval: 2_000},
  ]
  # other code
end

I removed _build directory and try to rebuild it but failed with same error message.

MyApp.MyStrategy ?

It was typo in this post.
I was doing MyApp.MyStrategy

For jwt tokens use Phoenix Token or guardian, they are tested and have a lot of tutorials.

I believe the module you need is “JokenJwks.DefaultStrategyTemplate”:

defmodule MyApp.MyStrategy do
  use JokenJwks.DefaultStrategyTemplate
  
  def init_opts(opts) do
    url = "https://www.googleapis.com/oauth2/v3/certs"
    Keyword.merge(opts, jwks_url: url)
  end
end

From what I can remember you should be good to go after that, but this isn’t the kind of code that requires frequent change so my memory is a bit weak there.

1 Like