<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="129584" data-post-id="129584">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="vinagrito1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/vinagrito1/120/15563_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  vinagrito1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Heya guys. So I’m another soul that struggled with something that was supposed to be much easier for a while. And finally landed here.<br>
So after trying all the libraries out there I’m sticking to JOSE. Thx <a class="mention" href="/u/dom" rel="nofollow">@dom</a> for mentioning it. As <a class="mention" href="/u/fireproofsocks" rel="nofollow">@fireproofsocks</a> pointed out previously</p>
<blockquote>
<p>I can run something like:</p>
</blockquote>
<pre data-code-wrap="elixir"><code class="lang-elixir">token = "from google oauth"
pem = "--- relevant key copied from https://www.googleapis.com/oauth2/v1/certs"
jwk = JOSE.JWK.from_pem(pem)
JOSE.JWT.verify_strict(jwk, ["RS256"], token)
</code></pre>
<p>Will do the job. Thank you all for the inputs</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="129584" data-batch-url="/posts/batch_likers">
                        7
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/using-joken-to-validate-google-jwts/19728/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-129584" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="129584"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="130381" data-post-id="130381">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="victorolinasc" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/victorolinasc/120/10667_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  victorolinasc
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Sorry for such a delayed response. I’ve replied <a class="mention" href="/u/fireproofsocks" rel="nofollow">@fireproofsocks</a> on Joken repo about RS keys configuration and released a more detailed configuration of asymmetric keys guide.</p>
<p>To validate tokens from Google, Microsoft and other that have an OpenID Connect certs endpoint (or similar) with a published JWKS, one can use JokenJwks.</p>
<p>You’d do simply:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule MyGoogleToken do
  use Joken.Config

  add_hook(JokenJwks, strategy: MyGoogleStrategy)

  def token_config do
    # your config here with what you want to validate from the token
  end
end

defmodule MyGoogleJwksStrategy do
  use JokenJwks.DefaultStrategyTemplate

  def init_opts(opts), do: [jwks_url: "https://www.googleapis.com/oauth2/v1/certs"]
end

defmodule MyApp do
  use Application

  def start(_type, _args) do
     children = 
      [
        MyGoogleStrategy,
        # others
      ]
      # other start logic
  end
</code></pre>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://hex.pm/packages/joken_jwks">
  <header class="source">
      <img src="https://hex.pm/images/hex-full-a8183c4f9adac71516516d107d402b18.svg?vsn=d" class="site-icon" alt="" width="136" height="120">

      <a href="https://hex.pm/packages/joken_jwks" target="_blank" rel="noopener nofollow">Hex</a>
  </header>

  <article class="onebox-body">
    <img width="160" height="160" src="https://hex.pm/images/favicon-160-3770bc59f1f8ba7656b4db5a1eacd8e3.png?vsn=d" class="thumbnail onebox-avatar" alt="">

<h3><a href="https://hex.pm/packages/joken_jwks" target="_blank" rel="noopener nofollow">joken_jwks</a></h3>

  <p>JWKS (JSON Web Keys Set) support for Joken2</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="130381" data-batch-url="/posts/batch_likers">
                        5
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/using-joken-to-validate-google-jwts/19728/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-130381" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="130381"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="134087" data-post-id="134087">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="rasbonics" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/rasbonics/120/15952_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  rasbonics
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This example would be an awesome addition to the Hex docs.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="134087" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/using-joken-to-validate-google-jwts/19728/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-134087" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="134087"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="170573" data-post-id="170573">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="spencerdcarlson" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/spencerdcarlson/120/14716_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  spencerdcarlson
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>If you are just interested in using Google’s certs to validate a JWT issued by them, I made the <a href="https://hex.pm/packages/google_certs" rel="nofollow">google_certs</a>  hex package.</p>
<p>The Google Certs package will download, cache, and auto refresh Google’s certs. Both <a href="https://www.googleapis.com/oauth2/v1/certs" rel="noopener nofollow ugc">v1</a> PEM format and <a href="https://www.googleapis.com/oauth2/v3/certs" rel="noopener nofollow ugc">v3</a> JWK format are supported and are ready to work with Joken (see <a href="https://hexdocs.pm/google_certs/GoogleCerts.html#fetch/1" rel="noopener nofollow ugc">GoogleCerts.fetch/1</a>). Here is the example from the <a href="https://hexdocs.pm/google_certs/readme.html#how-to-use-with-the-joken-library" rel="noopener nofollow ugc">how to use with joken</a> section in the docs:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule MyApp.Application do
  @moduledoc false

  use Application
  alias GoogleCerts.CertificateCache
  
  def start(_type, _args) do
    children = [
      CertificateCache
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule MyApp.Crypto.VerifyHook do
  @moduledoc false

  use Joken.Hooks

  @impl true
  def before_verify(_options, {jwt, %Joken.Signer{} = _signer}) do
    with {:ok, %{"kid" =&gt; kid}} &lt;- Joken.peek_header(jwt),
         {:ok, algorithm, key} &lt;- GoogleCerts.fetch(kid) do
      {:cont, {jwt, Joken.Signer.create(algorithm, key)}}
    else
      error -&gt; {:halt, {:error, :no_signer}}
    end
  end
end
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule MyApp.Crypto.JWTManager do
  @moduledoc false

  use Joken.Config, default_signer: nil

  @iss "https://accounts.google.com"
  
  # your google client id (usually ends in *.apps.googleusercontent.com)
  defp aud, do: Application.get_env(:my_app, :google_client_id) 

  # reference your custom verify hook here
  add_hook(MyApp.Crypto.VerifyHook) 

  @impl Joken.Config
  def token_config do
    default_claims(skip: [:aud, :iss])
    |&gt; add_claim("iss", nil, &amp;(&amp;1 == @iss))
    |&gt; add_claim("aud", nil, &amp;(&amp;1 == aud()))
  end
end
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir"># anywhere in your app you can verify and validate a Google issued JWT
iex&gt; jwt = "eyJhbGciOiJSUzI1..." # Google issued JWT (api call, uberauth, etc)
iex&gt; {:ok, claims} = JWTManager.verify_and_validate(jwt)
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="170573" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/using-joken-to-validate-google-jwts/19728/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-170573" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="170573"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>