zoedsoupe
I have this Guardian module:
defmodule Sntx.Guardian do
use Guardian, otp_app: :sntx
alias Sntx.Repo
alias Sntx.User.Account
def subject_for_token(user, _claims) do
sub = to_string(user.id)
{:ok, sub}
end
def resource_from_claims(claims) do
user = Repo.get(Account, claims["sub"])
{:ok, user}
end
def after_encode_and_sign(resource, claims, token, _options) do
with {:ok, _} <- Guardian.DB.after_encode_and_sign(resource, claims["typ"], claims, token) do
{:ok, token}
end
end
def on_verify(claims, token, _options) do
with {:ok, _} <- Guardian.DB.on_verify(claims, token) do
{:ok, claims}
end
end
def on_refresh({old_token, old_claims}, {new_token, new_claims}, _options) do
with {:ok, _, _} <- Guardian.DB.on_refresh({old_token, old_claims}, {new_token, new_claims}) do
{:ok, {old_token, old_claims}, {new_token, new_claims}}
end
end
def on_revoke(claims, token, _options) do
with {:ok, _} <- Guardian.DB.on_revoke(claims, token) do
{:ok, claims}
end
end
end
Then, if I try to execute Sntx.Guardian.encode_and_sign(%{id: "123"}) I receive this error:
** (CaseClauseError) no case clause matching: 43
(jose 1.11.5) src/base/jose_base64url.erl:136: :jose_base64url."-decode!/2-lbc$^0/2-0-"/2
(jose 1.11.5) src/base/jose_base64url.erl:136: :jose_base64url.decode!/2
(jose 1.11.5) src/jwk/jose_jwk_kty_oct.erl:50: :jose_jwk_kty_oct.from_map/1
(jose 1.11.5) src/jwk/jose_jwk.erl:304: :jose_jwk.from_map/1
(jose 1.11.5) lib/jose/jwk.ex:140: JOSE.JWK.from_map/1
(guardian 2.3.1) lib/guardian/token/jwt.ex:272: Guardian.Token.Jwt.create_token/3
(guardian 2.3.1) lib/guardian.ex:776: Guardian.returning_tuple/1
(guardian 2.3.1) lib/guardian.ex:602: Guardian.encode_and_sign/4
I’m really confused about this error. Any idea that what this means?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
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
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











First 5 of 5 Posts
zoedsoupe
There is a public repo here: https://github.com/zoedsoupe/sntx, on branch
feature/blog-postsal2o3cr
The basic cause is that a
+character (byte value 43) appears in a string that:jose_jwk.from_map/1treats as encoded in URL-safe Base64, which doesn’t allow that character. That behavior is directly from the specification forkty=oct.The root cause is that this incorrectly-encoded value is being set in
config/config.exsfrom an environment variable: https://github.com/zoedsoupe/sntx/blob/feature/blog-posts/config/config.exs#L30adamu
Not directly answering your question, but just in case
zoedsoupe
Oh thank you! I generated the token with
mix guardian.gen.secretbut it seem was generated with a+char!al2o3cr
Yeah, that’s a tricky one - the sets of characters used by
encode64andurl_encode64are nearly the same, so you got a bad roll of the dice.I created an issue on Guardian to address / document this:
https://github.com/ueberauth/guardian/issues/718