brunoripa

brunoripa

Hi,

I am using ueberauth/Guardian to authenticate users against google. It works, but I have a problem with keys rotations that google executes: ueberuath makes the challenge phase, and guardian receives the token and verifies it, extrapolating claims etc etc

My problem is that Google rotates the keys (which are here: https://www.googleapis.com/oauth2/v3/certs) and I don’t understand how to deal with such rotation. There’s no info on which one of the two to use. Also, reading here:

it states:

These keys are regularly rotated; examine the Cache-Control header in the response to determine when you should retrieve them again.

but does not tell anything more.

How should I handle this key rotation ? Which key should I use in what case ?

Thanks !

Showing Posts 1 to 5

OvermindDL1

OvermindDL1

OAuth2 gives access tokens to access user data, they have an expiration (Cache-Control) at which point the oauth2 server should be contacted again to update it or so (or if the user logged out of the oauth2 server then you’ll log them out of your system now too). Guardian I don’t think has anything to do with this whatsoever? Ueberauth just does the initial auth, it is up to ‘you’ to do it again later if needed.

tangui

tangui

You have to try validating signature against every suitable key. A suitable key is a key whose:

  • "use" member is not set or is set to "sig", and
  • "key_ops" member is not set or contains "verify", and
  • "alg" is not set or set to the OIDC client’s registered "id_token_signed_response_alg" if set (or the default "RS256" otherwise)

I’ve developed libs (JWKSURIUpdater and JWKUtils) for personal projects that you could be interested in.

brunoripa

brunoripa OP

I think I got the point. In the first part of the token [*], we have a bunch of information:

%{
  "alg" => "RS256",
  "kid" => "762fa637af953590db8bb8a636bf11d4360abc98",
  "typ" => "JWT"
}

The kid info is the one that gives us the chance to recognise which key has been used to generate the token you have received, and so which one to use to verify it.

So, what I have done, I have created a custom secret fetcher that applies this logic, and everything works. I am using it like this:

MyApp.GoogleGuardian.decode_and_verify(token, %{}, secret: SecretsFetcher.get(token))

The only feeling I have, is that maybe there is a way to implement this in a more Guardian-designed way; but I am struggling to find some real examples of this.


[*] the token is made of 3 parts, separated by a .; the first one is the one that contains the info (and it’s B64 encoded).

brunoripa

brunoripa OP

OAuth2 is made by two phases, with the first one being the “challenge” one, which is basically when you authorize the application after being redirected to the SSO implementation you are using (Google, in my case).

After this, ueberauth kingdom ends, and you have to handle the token. Guardian kicks in, but my question was about the multiple keys were to be used; this was the smoky part to me, sorry if I have not been very clear.

tangui

tangui

Indeed if a "kid" is present, you shall use it! With JOSE you can use JOSE.JWS.peek_protected/1 to retrieve the header.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New

Other Trending Topics Top

JesseHerrick
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
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews