Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support to set the Scope. #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion classes/loginflow/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,10 @@ protected function get_oidcclient() {
$redirecturi = (!empty($CFG->loginhttps)) ? str_replace('http://', 'https://', $CFG->wwwroot) : $CFG->wwwroot;
$redirecturi .= '/auth/oidc/';
$resource = (isset($this->config->oidcresource)) ? $this->config->oidcresource : null;
$scope = (isset($this->config->oidcscope)) ? $this->config->oidcscope : null;

$client = new \auth_oidc\oidcclient($this->httpclient);
$client->setcreds($clientid, $clientsecret, $redirecturi, $resource);
$client->setcreds($clientid, $clientsecret, $redirecturi, $resource, $scope);

$client->setendpoints(['auth' => $this->config->authendpoint, 'token' => $this->config->tokenendpoint]);
return $client;
Expand Down Expand Up @@ -456,6 +457,7 @@ protected function createtoken($oidcuniqid, $username, $authparams, $tokenparams
$tokenrec->oidcusername = $oidcusername;
$tokenrec->scope = !empty($tokenparams['scope']) ? $tokenparams['scope'] : 'openid profile email';
$tokenrec->resource = !empty($tokenparams['resource']) ? $tokenparams['resource'] : $this->config->oidcresource;
$tokenrec->scope = !empty($tokenparams['scope']) ? $tokenparams['scope'] : $this->config->oidcscope;
$tokenrec->authcode = $authparams['code'];
$tokenrec->token = $tokenparams['access_token'];
if (!empty($tokenparams['expires_on'])) {
Expand Down
16 changes: 13 additions & 3 deletions classes/oidcclient.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ public function __construct(\auth_oidc\httpclientinterface $httpclient) {
* @param string $secret The registered client secret.
* @param string $redirecturi The registered client redirect URI.
*/
public function setcreds($id, $secret, $redirecturi, $resource) {
public function setcreds($id, $secret, $redirecturi, $resource, $scope) {
$this->clientid = $id;
$this->clientsecret = $secret;
$this->redirecturi = $redirecturi;
$this->resource = (!empty($resource)) ? $resource : 'https://graph.windows.net';
$this->scope = (!empty($scope)) ? $scope : 'openid profile email';
}

/**
Expand Down Expand Up @@ -101,6 +102,15 @@ public function get_resource() {
return (isset($this->resource)) ? $this->resource : null;
}

/**
* Get the set scope.
*
* @return string The set scope.
*/
public function get_scope() {
return (isset($this->scope)) ? $this->scope : null;
}

/**
* Set OIDC endpoints.
*
Expand Down Expand Up @@ -132,7 +142,7 @@ protected function getauthrequestparams($promptlogin = false, array $stateparams
$params = [
'response_type' => 'code',
'client_id' => $this->clientid,
'scope' => 'openid profile email',
'scope' => $this->scope,
'nonce' => $nonce,
'response_mode' => 'form_post',
'resource' => $this->resource,
Expand Down Expand Up @@ -213,7 +223,7 @@ public function rocredsrequest($username, $password) {
'grant_type' => 'password',
'username' => $username,
'password' => $password,
'scope' => 'openid profile email',
'scope' => $this->scope,
'resource' => $this->resource,
'client_id' => $this->clientid,
'client_secret' => $this->clientsecret,
Expand Down
4 changes: 3 additions & 1 deletion lang/cs/auth_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@
$string['cfg_loginflow_authcode_desc'] = 'Při použití tohoto postupu uživatel na přihlašovací stránce Moodlu klikne na ikonu poskytovatele identity (viz výše „Název poskytovatele“) a je následně přesměrován na poskytovatele, aby se přihlásil. Po úspěšném přihlášení je uživatel přesměrován zpět do Moodlu, kde proběhne transparentní přihlášení do Moodlu. Toto je nejstandardizovanější bezpečný způsob přihlašování uživatelů.';
$string['cfg_loginflow_rocreds'] = 'Ověřování uživatelské_jméno/heslo';
$string['cfg_loginflow_rocreds_desc'] = 'Při použití tohoto postupu uživatel zadá své uživatelské jméno a heslo do přihlašovacího formuláře Moodlu, obdobně jako při ručním přihlášení. Jeho přihlašovací údaje jsou pak na pozadí předány poskytovateli identity, aby bylo získáno ověření. Tento postup je pro uživatele nejtransparentnější, protože nemá žádný přímý kontakt s poskytovatelem identity. Ne všichni poskytovatelé identity ale tento postup podporují.';
$string['cfg_oidcresource_key'] = 'Zdroj';
$string['cfg_oidcresource_key'] = 'Rozsah';
$string['cfg_oidcresource_desc'] = 'Zdroj OpenID Connect, pro který se odesílá požadavek.';
$string['cfg_oidcscope_key'] = 'Scope';
$string['cfg_oidcscope_desc'] = 'Rozsah OIDC, který se má použít.';
$string['cfg_opname_key'] = 'Název poskytovatele';
$string['cfg_opname_desc'] = 'Toto je údaj zobrazovaný koncovému uživateli, který identifikuje, jaký typ přihlašovacích údajů potřebuje uživatel použít k přihlášení. Tento údaj se používá na více místech rozhraní pro koncového uživatele v tomto pluginu k identifikaci vašeho poskytovatele.';
$string['cfg_redirecturi_key'] = 'URI pro přesměrování';
Expand Down
2 changes: 2 additions & 0 deletions lang/de/auth_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
$string['cfg_loginflow_rocreds_desc'] = 'Mit diesem Fluss gibt der Benutzer wie bei einer manuellen Anmeldung seinen Benutzernamen und sein Kennwort im Moodle-Anmeldeformular ein. Die Anmeldedaten werden dann im Hintergrund zur Authentifizierung an den Identitätsprovider übermittelt. Dieser Fluss ist für den Benutzer am transparentesten, da er keine direkte Interaktion mit dem Identitätsprovider hat. Alle Identitätsprovider unterstützen diesen Fluss.';
$string['cfg_oidcresource_key'] = 'Ressource';
$string['cfg_oidcresource_desc'] = 'Die OpenID Connect-Ressource, für die die Anfrage gesendet wird.';
$string['cfg_oidcscope_key'] = 'Umfang';
$string['cfg_oidcscope_desc'] = 'Der zu verwendende OIDC-Bereich.';
$string['cfg_opname_key'] = 'Providername';
$string['cfg_opname_desc'] = 'Hierbei handelt es sich um eine Bezeichnung für den Endbenutzer, die den Typ der Anmeldedaten kennzeichnet, die der Benutzer für die Anmeldung verwenden muss. Diese Bezeichnung wird in allen benutzerorientierten Teilen dieses Plugins zur Identifizierung Ihres Providers verwendet.';
$string['cfg_redirecturi_key'] = 'Weiterleitungs-URI';
Expand Down
2 changes: 2 additions & 0 deletions lang/en/auth_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
$string['cfg_loginflow_rocreds_desc'] = 'Using this flow, the user enters their username and password into the Moodle login form like they would with a manual login. This will authorize the user with the identity provider, but will not create a session on the identity provider\'s site. For example, if using Office 365 with OpenID Connect, the user will be logged in to Moodle but not the Office 365 web applications. Using the authorization request is recommended if you want users to be logged in to both Moodle and the identity provider. Note that not all identity providers support this flow. This option should only be used when other authorization grant types are not available.';
$string['cfg_oidcresource_key'] = 'Resource';
$string['cfg_oidcresource_desc'] = 'The OpenID Connect resource for which to send the request.';
$string['cfg_oidcscope_key'] = 'Scope';
$string['cfg_oidcscope_desc'] = 'The OIDC Scope to use.';
$string['cfg_opname_key'] = 'Provider Name';
$string['cfg_opname_desc'] = 'This is an end-user-facing label that identifies the type of credentials the user must use to login. This label is used throughout the user-facing portions of this plugin to identify your provider.';
$string['cfg_redirecturi_key'] = 'Redirect URI';
Expand Down
4 changes: 3 additions & 1 deletion lang/es/auth_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@
$string['cfg_loginflow_authcode_desc'] = 'Al utiliza este flujo, el usuario hace clic en el nombre del proveedor de identidad (consulte "Nombre del proveedor" más arriba) en la página de inicio de sesión de Moodle y es redireccionado al proveedor para iniciar sesión. Una vez que haya iniciado sesión correctamente, es redireccionado de vuelta a Moodle, donde se realiza el inicio de sesión de manera transparente. Esta es la forma más segura y estandarizada de inicio de sesión del usuario.';
$string['cfg_loginflow_rocreds'] = 'Autenticación de nombre de usuario/contraseña';
$string['cfg_loginflow_rocreds_desc'] = 'Al usar este flujo, el usuario ingresa el nombre de usuario y la contraseña al formulario de inicio de sesión de Moodle como lo haría de manera manual. Luego, las credenciales se pasan al proveedor de identidad en el segundo plano para obtener la autenticación. Este flujo es la forma más transparente para el usuario ya que no posee interacción directa con el proveedor de identidad. Tenga en cuenta que no todos los proveedores de identidad admiten este flujo.';
$string['cfg_oidcresource_key'] = 'Recurso';
$string['cfg_oidcresource_key'] = 'Alcance';
$string['cfg_oidcresource_desc'] = 'El recurso de OpenID Connect para el cual enviar la solicitud.';
$string['cfg_oidcscope_key'] = 'Scope';
$string['cfg_oidcscope_desc'] = 'El alcance de OIDC a utilizar.';
$string['cfg_opname_key'] = 'Nombre del proveedor';
$string['cfg_opname_desc'] = 'Esta es una etiqueta que apunta al usuario final e identifica el tipo de credenciales que el usuario debe utilizar para iniciar sesión. Esta etiqueta se utiliza durante todas las partes que apuntan al usuario de este complemento para identificar al proveedor.';
$string['cfg_redirecturi_key'] = 'URI de redireccionamiento';
Expand Down
2 changes: 2 additions & 0 deletions lang/fi/auth_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
$string['cfg_loginflow_rocreds_desc'] = 'Jos tämä kirjautumiskulku on käytössä, käyttäjä kirjautuu Moodleen antamalla käyttäjänimen ja salasanan Moodlen kirjautumislomakkeeseen. Tunnistetiedot välitetään taustalla identiteetintarjoajalle todennusta varten. Tämä kulku on läpinäkyvin käyttäjän kannalta, koska käyttäjä ei ole suoraan tekemisissä identiteetintarjoajan kanssa. Huomaa, että kaikki identiteetintarjoajat eivät tue tätä kulkua.';
$string['cfg_oidcresource_key'] = 'Resurssi';
$string['cfg_oidcresource_desc'] = 'OpenID Connect -resurssi, jota lähetettävä pyyntö koskee.';
$string['cfg_oidcscope_key'] = 'laajuus';
$string['cfg_oidcscope_desc'] = 'Käytettävä OIDC-soveltamisala.';
$string['cfg_opname_key'] = 'Palveluntarjoajan nimi';
$string['cfg_opname_desc'] = 'Tämä on loppukäyttäjälle näkyvä selite, joka ilmoittaa kirjautumiseen käytettävien tunnistetietojen tyypin. Tätä palveluntarjoajan selitettä käytetään tämän lisäosan kaikissa käyttäjälle näkyvissä osioissa.';
$string['cfg_redirecturi_key'] = 'Uudelleenohjauksen URI';
Expand Down
2 changes: 2 additions & 0 deletions lang/fr/auth_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
$string['cfg_loginflow_rocreds_desc'] = 'À l\'aide de cette méthode, l\'utilisateur saisit son nom d\'utilisateur et son mot de passe dans le formulaire de connexion Moodle comme il le ferait avec une connexion manuelle. Ses informations d\'identification sont ensuite transmises au fournisseur d\'identité en arrière-plan pour obtenir son authentification. Cette méthode est la plus transparente pour l\'utilisateur car il n\'a aucune interaction directe avec le fournisseur d\'identité. Notez que l\'ensemble des fournisseurs d\'identité prennent en charge ce flux.';
$string['cfg_oidcresource_key'] = 'Ressource';
$string['cfg_oidcresource_desc'] = 'Ressource OpenID Connect pour laquelle envoyer la demande.';
$string['cfg_oidcscope_key'] = 'Porté';
$string['cfg_oidcscope_desc'] = 'L\'étendue OIDC à utiliser.';
$string['cfg_opname_key'] = 'Nom du fournisseur';
$string['cfg_opname_desc'] = 'Il s\'agit d\'une étiquette destinée à l\'utilisateur final qui identifie le type d\'informations d\'identification dont l\'utilisateur doit se servir pour se connecter. Cette étiquette est utilisée sur toutes les sections permettant d\'identifier votre fournisseur et qui sont visibles par l\'utilisateur.';
$string['cfg_redirecturi_key'] = 'URI de redirection';
Expand Down
2 changes: 2 additions & 0 deletions lang/it/auth_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
$string['cfg_loginflow_rocreds_desc'] = 'Utilizzando questo flusso, l\'utente inserisce il nome utente e la password nel modulo di login di Moodle seguendo la stessa procedura del login manuale. Le credenziali vengono quindi passate all\'Identity Provider in background per ottenere l\'autenticazione. Questo flusso è quello più trasparente per l\'utente in quanto non esiste interazione diretta con l\'Identity Provider. Osservare che non tutti gli Identity Provider supportano questo flusso.';
$string['cfg_oidcresource_key'] = 'Risorsa';
$string['cfg_oidcresource_desc'] = 'La risorsa OpenID Connect per la quale inviare la richiesta.';
$string['cfg_oidcscope_key'] = 'Scopo';
$string['cfg_oidcscope_desc'] = 'L\'ambito OIDC da utilizzare.';
$string['cfg_opname_key'] = 'Nome del provider';
$string['cfg_opname_desc'] = 'Si tratta di un\'etichetta presentata all\'utente finale che identifica il tipo di credenziali che l\'utente deve utilizzare per eseguire il login. Questa etichetta viene utilizzata in tutta la parte rivolta all\'utente del plugin per identificare il provider.';
$string['cfg_redirecturi_key'] = 'URI di reindirizzamento';
Expand Down
2 changes: 2 additions & 0 deletions lang/ja/auth_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
$string['cfg_loginflow_rocreds_desc'] = 'このフローでは、手動によるログインと同様、ユーザはMoodleのログインフォームにユーザ名とパスワードを入力します。これらの認証情報はバックグラウンドでアイデンティティプロバイダに渡され、認証を取得します。ユーザはアイデンティティプロバイダと直接やり取りしないので、このフローはユーザに最も透過的です。すべてのアイデンティティプロバイダがこのフローをサポートしているわけではない点にご注意ください。';
$string['cfg_oidcresource_key'] = 'リソース';
$string['cfg_oidcresource_desc'] = 'リクエストを送る、OpenID Connectのリソース。';
$string['cfg_oidcscope_key'] = '範囲';
$string['cfg_oidcscope_desc'] = '使用するOIDCスコープ。';
$string['cfg_opname_key'] = 'プロバイダ名';
$string['cfg_opname_desc'] = 'これはユーザがログインするために使用する必要がある認証情報の種類を識別するラベルで、エンドユーザに表示されます。このラベルはプロバイダを識別するために、このプラグインのユーザに表示されるすべての部分で使用されます。';
$string['cfg_redirecturi_key'] = 'リダイレクトURI';
Expand Down
2 changes: 2 additions & 0 deletions lang/nl/auth_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
$string['cfg_loginflow_rocreds_desc'] = 'In deze flow voert de gebruiker zijn gebruikersnaam en wachtwoord in het aanmeldingsformulier van Moodle in, net als bij een handmatige aanmelding. De referenties van de gebruiker worden daarna op de achtergrond doorgegeven aan de identiteitsprovider om authenticatie te verkrijgen. Deze werkwijze is de meest transparante voor de gebruiker omdat er geen directe interactie is met de identiteitsprovider. Niet alle identiteitsproviders ondersteunen deze werkwijze.';
$string['cfg_oidcresource_key'] = 'Bron';
$string['cfg_oidcresource_desc'] = 'De OpenID Connect-bron waarvoor het verzoek moet worden verzonden.';
$string['cfg_oidcscope_key'] = 'Reikwijdte';
$string['cfg_oidcscope_desc'] = 'De te gebruiken OIDC-reikwijdte.';
$string['cfg_opname_key'] = 'Naam provider';
$string['cfg_opname_desc'] = 'Dit is een voor de gebruiker zichtbaar label dat aangeeft met welke type referenties de gebruiker zich moet aanmelden. Dit label wordt in alle voor de gebruiker zichtbare delen van deze plugin gebruikt om de provider aan te geven.';
$string['cfg_redirecturi_key'] = 'Omleidings-URL';
Expand Down
2 changes: 2 additions & 0 deletions lang/pl/auth_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
$string['cfg_loginflow_rocreds_desc'] = 'W przypadku tego przepływu użytkownik wprowadza nazwę użytkownika i hasło do formularza logowania się do platformy Moodle w taki sam sposób jak w przypadku logowania ręcznego. Dane logowania użytkownika są następnie przesyłane do dostawcy tożsamości w tle w celu uwierzytelnienia. Ten przepływ jest najbardziej niewidoczny dla użytkownika, ponieważ użytkownik nie wchodzi w bezpośrednią interakcję z dostawcą tożsamości. Nie wszyscy dostawcy tożsamości obsługują ten przepływ.';
$string['cfg_oidcresource_key'] = 'Zasób';
$string['cfg_oidcresource_desc'] = 'Zasób wtyczki OpenID Connect, do którego ma zostać wysłane żądanie.';
$string['cfg_oidcscope_key'] = 'Scope';
$string['cfg_oidcscope_desc'] = 'Zakres OIDC do użycia.';
$string['cfg_opname_key'] = 'Nazwa dostawcy';
$string['cfg_opname_desc'] = 'Jest to etykieta dla użytkownika końcowego określająca rodzaj danych logowania, których użytkownik musi użyć do logowania. Ta etykieta jest używana w obszarach wtyczki widocznych dla użytkownika w celu zidentyfikowania dostawcy.';
$string['cfg_redirecturi_key'] = 'Adres URI przekierowania';
Expand Down
2 changes: 2 additions & 0 deletions lang/pt_br/auth_oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
$string['cfg_loginflow_rocreds_desc'] = 'Ao usar esse fluxo, o usuário informará seu nome de usuário e sua senha no formulário de login do Moodle da mesma forma que faria em um login manual. As credenciais serão, então, transmitidas em segundo plano para o provedor de identidade no intuito de obter a autenticação. Esse fluxo é o mais simples para o usuário, pois ele não interage diretamente com o provedor de identidade. Tenha em mente que nem todos os provedores de identidade aceitam a utilização desse fluxo.';
$string['cfg_oidcresource_key'] = 'Recurso';
$string['cfg_oidcresource_desc'] = 'O recurso do OpenID Connect para o qual a solicitação deverá ser enviada.';
$string['cfg_oidcscope_key'] = 'Escopo';
$string['cfg_oidcscope_desc'] = 'O escopo do OIDC a ser usado.';
$string['cfg_opname_key'] = 'Nome do provedor';
$string['cfg_opname_desc'] = 'Esse é um rótulo visível para o usuário que identifica o tipo de credenciais que devem ser utilizadas pelo usuário no login. Esse rótulo é usado em todas as partes visíveis para o usuário deste plugin para a identificação do seu provedor.';
$string['cfg_redirecturi_key'] = 'URI de redirecionamento';
Expand Down
5 changes: 5 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
$configdefault = 'https://graph.windows.net';
$settings->add(new admin_setting_configtext('auth_oidc/oidcresource', $configkey, $configdesc, $configdefault, PARAM_TEXT));

$configkey = new lang_string('cfg_oidcscope_key', 'auth_oidc');
$configdesc = new lang_string('cfg_oidcscope_desc', 'auth_oidc');
$configdefault = 'openid profile email';
$settings->add(new admin_setting_configtext('auth_oidc/oidcscope', $configkey, $configdesc, $configdefault, PARAM_TEXT));

$configkey = new lang_string('cfg_redirecturi_key', 'auth_oidc');
$configdesc = new lang_string('cfg_redirecturi_desc', 'auth_oidc');
$settings->add(new \auth_oidc\form\adminsetting\redirecturi('auth_oidc/redirecturi', $configkey, $configdesc));
Expand Down