freewebwithme
Trying to verify google idToken using Joken & JokenJwks
Hi
I am trying to verify and validate idToken jwt from google oauth to sign in and create a user.
I am using Joken and JokenJwks
my_strategy.ex
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
google_token.ex
defmodule MyApp.GoogleToken do
use Joken.Config
add_hook(JokenJwks, strategy: MyApp.MyStrategy)
#@impl true
def token_config do
# validate from the token
default_claims()
|> add_claim("iss", nil, &(&1 == "https://accounts.google.com"))
|> add_claim("aud", nil, &(&1 == "client_app_id"))
end
end
application.ex
def start(_type, _args) do
# List all child processes to be supervised
children = [
# other code,,,,
{MyApp.MyStrategy, time_interval: 60_000},
]
# other code..
end
in iex session
token = "idToken"
token_config = GoogleToken.token_config()
then I called
GoogleToken.verify_and_validate(token_configs, token)
and got an error
(FunctionClauseError) no function clause matching in Joken.verify/3
Attempted function clauses (showing 3 out of 3):
def verify(bearer_token, nil, hooks) when is_binary(bearer_token) and is_list(hooks)
def verify(bearer_token, signer, hooks) when is_binary(bearer_token) and is_atom(signer)
def verify(bearer_token, signer = %Joken.Signer{}, hooks) when is_binary(bearer_token)
(joken) lib/joken.ex:242: Joken.verify/3
(joken) lib/joken.ex:296: Joken.verify_and_validate/5
What am I missing?
Marked As Solved
victorolinasc
Hey, let’s see if I can help.
You don’t need to pass the configuration for verify_and_validate of your module. All you need is
GoogleToken.verify_and_validate(token).
You pass the config as a first parameter when you use Joken.verify_and_validate directly.
Hope it helps.
1
Popular in Questions
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
I have a super simple question about elixir - how would I take a file like this
foo
bar
baz
and output a new file that enumerates th...
New
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Other popular topics
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









