# How to get PUBLIC KEY PEM from jwks.json

**URL:** <https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355>\
**Category:** JWT.io\
**Created:** [March 31, 2021, 9:58am UTC](https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355 "2021-03-31T09:58:46Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![dch](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dch/32/28483_2.png) [@dch](https://community.auth0.com/u/dch)\
**Post date:** [March 31, 2021, 9:58am UTC](https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355/1 "2021-03-31T09:58:47Z")

</div>

Our backend application requires the public cert of the signing key, in PEM format.

The `jwks.json` url at [https://domainauth0.com/.well-known/jwks.json](https://domainauth0.com/.well-known/jwks.json) spits back:

```json
{
  "keys": [
    {
      "alg": "RS256",
      "kty": "RSA",
      "use": "sig",
      "n": "...",
      "e": "....",
      "kid": "...",
      "x5t": "...",
      "x5c": ["...="
      ]
    },
...

```

The `x5c` array looks _almost_ right, but it’s clearly not the right format for our application, which expects:

```auto
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQE...
BAQUAA4GNADCBiQKBg...
QDdlatRjRjogo3WojgGH....
-----END PUBLIC KEY-----

```

What’s the simplest way to get this public cert? Is it related to the Signing Certificate available in the advanced section of the auth0 tenant application?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 31, 2021, 3:10pm UTC](https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355/3 "2021-03-31T15:10:23Z")

</div>

Hi @dch,

Welcome to the Community!

You can quickly get the PEM formatted public ~~key~~ cert from the /pem endpoint.

For example:

```python
https://my-auth0-domain.com/pem

```

---

<div class="post-metadata">

**Author:** ![dch](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dch/32/28483_2.png) [@dch](https://community.auth0.com/u/dch)\
**Post date:** [March 31, 2021, 3:20pm UTC](https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355/4 "2021-03-31T15:20:08Z")

</div>

I tried this earlier, and it’s not sufficient. It returns this format:

```auto
-----BEGIN CERTIFICATE-----
MIIDDTCCAfWgAwIBAgIJIuh42TrceKqdMA0GCSqGSIb3DQEBCwUAMCQxI...

```

Which looks like CRT to me, not PEM, I’m no expert here.

However this worked:

```auto
$ curl -s https://:domain.auth0.com/pem | openssl x509 -pubkey -noout

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsIhk...

```

Can you shed any light on why these 2 formats are different?

thanks Dan!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 31, 2021, 3:51pm UTC](https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355/5 "2021-03-31T15:51:37Z")

</div>

It looks like the cert you get from the /pem endpoint is a public certificate that contains other information in addition to the public key. If you decode it, you can see other information.

The result from your openSSL command extracts the public key from the original cert.

My original response said you could get the PEM formatted public key from the /pem endpoint, which is not exactly correct. It looks like you get a PEM formatted cert that _contains_ the public key. I’ll edit it.

---

<div class="post-metadata">

**Author:** ![dch](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dch/32/28483_2.png) [@dch](https://community.auth0.com/u/dch)\
**Post date:** [March 31, 2021, 3:54pm UTC](https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355/6 "2021-03-31T15:54:13Z")

</div>

thanks Dan! It would be _excellent_ to have an easily fetchable endpoint that provides the cert. This way https://:domain.auth0.com/.well-known/jwks.json or similar would allow us to always have the up to date keys even in the event of key rotation. Great for automated devops.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 31, 2021, 3:57pm UTC](https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355/7 "2021-03-31T15:57:57Z")

</div>

You should be using the JWKS endpoint to do that.

---

<div class="post-metadata">

**Author:** ![dch](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dch/32/28483_2.png) [@dch](https://community.auth0.com/u/dch)\
**Post date:** [March 31, 2021, 4:01pm UTC](https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355/8 "2021-03-31T16:01:44Z")

</div>

It was in fact the first thing I tried. How does one go from seeing this and being largely confused:

```auto
{
  "keys": [
    {
      "alg": "RS256",
      "kty": "RSA",
      "use": "sig",
      "n": "...",
      "e": "...,
      "kid": "...",
      "x5t": "...",
      "x5c": [
        "MIIDDTCCA...

```

To knowing aah yeah `MIIDDTCCA` I recognise that. Clear as mud, that’s obviously the contents of a CRT encoded cert and I’ll just whip out openssl to translate that into the public key I actually need?

And is it, in fact, that pub-key I need? I’m still not clear on that?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 31, 2021, 4:15pm UTC](https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355/9 "2021-03-31T16:15:02Z")

</div>

What framework/language are you using? There are libraries that handle all of this for you, you shouldn’t have to manually set anything unless you are wanting to or have a very specific use-case. Most of our SDKs allow you to set a domain and will retrieve your public key automatically.

---

<div class="post-metadata">

**Author:** ![dch](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dch/32/28483_2.png) [@dch](https://community.auth0.com/u/dch)\
**Post date:** [March 31, 2021, 4:19pm UTC](https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355/10 "2021-03-31T16:19:54Z")

</div>

- Elixir with UeberAuth plugin [GitHub - achedeuzot/ueberauth\_auth0: Auth0 OAuth2 strategy for Überauth.](https://github.com/achedeuzot/ueberauth_auth0) to do the “oauth dance”

- using the provided token to as HTTP Authorization Bearer token to Apache CouchDB [1.2.23. Authentication — Apache CouchDB® 3.3 Documentation](https://docs.couchdb.org/en/stable/api/server/authn.html#jwt-authentication)

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 31, 2021, 4:41pm UTC](https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355/11 "2021-03-31T16:41:07Z")

</div>

Thanks. So you want to verify JWTs directly in your CouchDB? That is where you need the PEM formatted public key?

---

<div class="post-metadata">

**Author:** ![dch](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dch/32/28483_2.png) [@dch](https://community.auth0.com/u/dch)\
**Post date:** [March 31, 2021, 4:41pm UTC](https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355/12 "2021-03-31T16:41:53Z")

</div>

Yep. I have this working, but only with the `---- BEGIN PUBLIC KEY ----` style format.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [April 15, 2021, 4:42pm UTC](https://community.auth0.com/t/how-to-get-public-key-pem-from-jwks-json/60355/13 "2021-04-15T16:42:15Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
