NAME
Mojo::OIDC - a safe and simple OpenID Connect implementation.
VERSION
version 0.001
SYNOPSIS
my $metadata = Mojo::OIDC::Metadata->new_from_discovery($url);
my $client = $metadata->create_client(client_id => 'me');
my ($url, $ticket) = $client->create_authorization_request(%args);
... # Redirect to $url, and wait for a response
my $authorization = $client->accept_authorization_response($response, $ticket);
my $tokens = $authorization->get_tokens;
my $id_claims = $client->validate_token($tokens->id_token, $ticket);
DESCRIPTION
This a subclass of Mojo::OAuth2, specialized in interacting with OpenID Connect Identity Providers.
METHODS
create_authorization_request
This overrides the create_authorization_request. It will add the following named arguments to its parent:
nonce-
String value used to associate a Client session with an ID Token, and to mitigate replay attacks. The value is passed through unmodified from the Authentication Request to the ID Token.
If no value was given a random value will be generated; this can disabled by passing undef as value.
prompt-
Space-delimited, case-sensitive list of ASCII string values that specifies whether the Authorization Server prompts the End-User for reauthentication and consent. The defined values are:
none,login,concentandselect_account. max_age-
Maximum Authentication Age. Specifies the allowable elapsed time in seconds since the last time the End-User was actively authenticated by the OP. If the elapsed time is greater than this value, the OP MUST attempt to actively re-authenticate the End-User. When max_age is used, the ID Token returned MUST include an auth_time Claim Value. Note that
max_age=0is equivalent toprompt=login. display-
ASCII string value that specifies how the Authorization Server displays the authentication and consent user interface pages to the End-User. The defined values are:
page,popup,touchandwap. ui_locales-
End-User's preferred languages and scripts for the user interface, represented as a space-separated list of BCP47 [RFC5646] language tag values acr_values-
Requested Authentication Context Class Reference values. Space-separated string that specifies the acr values that the Authorization Server is being requested to use for processing this Authentication Request, with the values appearing in order of preference. The Authentication Context Class satisfied by the authentication performed is returned as the acr Claim Value. The acr Claim is requested as a Voluntary Claim by this parameter.
login_hint-
Hint to the Authorization Server about the login identifier the End-User might use to log in (if necessary). This hint can be used by an RP if it first asks the End-User for their e-mail address (or other identifier) and then wants to pass that value as a hint to the discovered authorization service. It is RECOMMENDED that the hint value match the value used for discovery.
id_token_hint-
ID Token previously issued by the Authorization Server being passed as a hint about the End-User's current or past authenticated session with the Client. If the End-User identified by the ID Token is already logged in or is logged in as a result of the request (with the OP possibly evaluating other information beyond the ID Token in this decision), then the Authorization Server returns a positive response; otherwise, it MUST return an error, such as login_required. When possible, an id_token_hint SHOULD be present when prompt=none is used and an invalid_request error MAY be returned if it is not; however, the server SHOULD respond successfully when possible, even if it is not present.
Additionally, it will add the openid scope if it isn't enabled already.
validate_id_token
my $id_claim = $client->validate_id_token($id_token, $ticket);
This will validate the ID token, and return its claims on success (or throw an exception otherwise).
AUTHOR
Leon Timmermans <fawaka@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.