lib/kitten_blue/jwk/apple.ex

defmodule KittenBlue.JWK.Apple do
  @moduledoc """
  Handling module for Apple Public JWKs
  """

  # see https://developer.apple.com/documentation/signinwithapplerestapi/fetch_apple_s_public_key_for_verifying_token_signature
  @apple_jwks_uri "https://appleid.apple.com/auth/keys"

  @doc """
  This function fetch Google JWK Sets and return the list of `KittenBlue.JWK`.

  ## Examples

      iex> KittenBlue.JWK.Apple.fetch!()
  [
  %KittenBlue.JWK{
    alg: "RS256",
    key: %JOSE.JWK{
      fields: %{"alg" => "RS256", "kid" => "86D88Kf", "use" => "sig"},
      keys: :undefined,
      kty: {:jose_jwk_kty_rsa,
       {:RSAPublicKey,
        17218976569472171392328766014351377623938190083704822988840858688583589896863690045137023711927931738801630749991914274954014356859870680594196182611436747369851336392150075102120538286646249274018948394939836954815229462134159727313036618616032886754027200534323811097683662906642261006948466488145990076973456988733603209200724856954702255734860429888106995022522513220031897987764861386973776593534699456365388097222751247511386677812517323312227868237294568748794665988814638685917058844978108485387332854052607802543387482783439171585055095101620099686424858380607382460209305193934705911563703225852424512195521,
        65537}}
    },
    kid: "86D88Kf"
  },
  %KittenBlue.JWK{
    alg: "RS256",
    key: %JOSE.JWK{
      fields: %{"alg" => "RS256", "kid" => "eXaunmL", "use" => "sig"},
      keys: :undefined,
      kty: {:jose_jwk_kty_rsa,
       {:RSAPublicKey,
        28506959526187058747258525626430938169704725204900526126844083433565751408411494176847637835421193860534595320364447575403468743566499123150300411809834024184195777130663440969659283758913985881923388671973516521122022988964740033971585857996186125352277170962488494163509421647472675123477144074010130241049022712224851924853667700032097975111612938674339911163977966896126177819217844243460102664711470062131611845259215719572214376544337566036425374345989397224110217335993021299491318557930102279952890712915227836029514247217600545540614032933399445683174911113458307244986296233260868205395173861403326852440519,
        65537}}
    },
    kid: "eXaunmL"
  }
  ]

  """
  @spec fetch!() :: [KittenBlue.JWK.t()] | nil
  def fetch!(), do: KittenBlue.JWK.fetch!(@apple_jwks_uri)
end