.. index:: single: open_id_pkce
.. _open_id_pkce/0:

.. rst-class:: right

**object**

``open_id_pkce``
================

PKCE and authorization-request helpers for OpenID Connect clients.

| **Availability:** 
|    ``logtalk_load(open_id(loader))``

| **Author:** Paulo Moura
| **Version:** 1:0:0
| **Date:** 2026-07-08

| **Compilation flags:**
|    ``static, context_switching_calls``


| **Imports:**
|    ``public`` :ref:`open_id_helpers <open_id_helpers/0>`
| **Uses:**
|    :ref:`crypto <crypto/0>`
|    :ref:`sha256 <sha256/0>`
|    :ref:`user <user/0>`

| **Remarks:**
|    (none)

| **Inherited public predicates:**
|     :ref:`options_protocol/0::check_option/1`  :ref:`options_protocol/0::check_options/1`  :ref:`options_protocol/0::default_option/1`  :ref:`options_protocol/0::default_options/1`  :ref:`options_protocol/0::option/2`  :ref:`options_protocol/0::option/3`  :ref:`options_protocol/0::valid_option/1`  :ref:`options_protocol/0::valid_options/1`  

.. contents::
   :local:
   :backlinks: top

Public predicates
-----------------

.. index:: code_verifier/2
.. _open_id_pkce/0::code_verifier/2:

``code_verifier/2``
^^^^^^^^^^^^^^^^^^^

Returns a valid PKCE code verifier, either provided in options or freshly generated.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``code_verifier(Verifier,Options)``
| **Mode and number of proofs:**
|    ``code_verifier(-atom,+list(compound))`` - ``one_or_error``

| **Exceptions:**
|    ``Options`` is a variable or a partial list:
|        ``instantiation_error``
|    ``Options`` is neither a variable nor a list:
|        ``type_error(list,Options)``
|    An element ``Option`` of the list ``Options`` is neither a variable nor a compound term:
|        ``type_error(compound,Option)``
|    An element ``Option`` of the list ``Options`` is a compound term but not a valid option:
|        ``domain_error(option,Option)``
|    ``Verifier`` is a variable:
|        ``instantiation_error``
|    ``Verifier`` is not a valid PKCE code verifier:
|        ``domain_error(open_id_code_verifier,Verifier)``


------------

.. index:: code_challenge/2
.. _open_id_pkce/0::code_challenge/2:

``code_challenge/2``
^^^^^^^^^^^^^^^^^^^^

Computes the S256 PKCE code challenge for a code verifier.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``code_challenge(Verifier,Challenge)``
| **Mode and number of proofs:**
|    ``code_challenge(+atom,-atom)`` - ``one_or_error``

| **Exceptions:**
|    ``Verifier`` is a variable:
|        ``instantiation_error``
|    ``Verifier`` is not a valid PKCE code verifier:
|        ``domain_error(open_id_code_verifier,Verifier)``


------------

.. index:: authorization_url/5
.. _open_id_pkce/0::authorization_url/5:

``authorization_url/5``
^^^^^^^^^^^^^^^^^^^^^^^

Builds an authorization URL and session data for an Authorization Code plus PKCE flow.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``authorization_url(Provider,Request,URL,Session,Options)``
| **Mode and number of proofs:**
|    ``authorization_url(+compound,+compound,-atom,-compound,+list(compound))`` - ``one_or_error``

| **Exceptions:**
|    ``Request`` is neither a direct options list nor a request wrapper term containing an options list:
|        ``domain_error(open_id_options,Request)``
|    ``Options`` is a variable or a partial list:
|        ``instantiation_error``
|    ``Options`` is neither a variable nor a list:
|        ``type_error(list,Options)``
|    An element ``Option`` of the list ``Options`` is neither a variable nor a compound term:
|        ``type_error(compound,Option)``
|    An element ``Option`` of the list ``Options`` is a compound term but not a valid option:
|        ``domain_error(option,Option)``
|    ``Request`` is missing a required authorization request option:
|        ``domain_error(open_id_authorization_request,missing(Name))``
|    A request value that must be an atom is not an atom:
|        ``type_error(atom,Value)``
|    A scope value is neither an atom nor a list of atoms:
|        ``domain_error(open_id_space_separated_atom,Value)``
|    The PKCE code verifier is a variable:
|        ``instantiation_error``
|    The PKCE code verifier is not valid:
|        ``domain_error(open_id_code_verifier,Verifier)``


------------

Protected predicates
--------------------

(no local declarations; see entity ancestors if any)

Private predicates
------------------

(no local declarations; see entity ancestors if any)

Operators
---------

(none)

