dolibarr 23.0.3
openid_connect.lib.php
1<?php
2/* Copyright (C) 2017 Open-DSI <support@open-dsi.fr>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
30function openid_connect_get_state()
31{
32 return hash('sha256', session_id());
33}
34
35
41function openid_connect_get_redirect_url()
42{
43 return DOL_MAIN_URL_ROOT . '/core/modules/openid_connect/callback.php';
44}
45
46
52function openid_connect_get_url()
53{
54 // Note: For the scope, we msut use rawurlencode instead of urlencode.
55 $url = getDolGlobalString('MAIN_AUTHENTICATION_OIDC_AUTHORIZE_URL').'?client_id='.urlencode(getDolGlobalString('MAIN_AUTHENTICATION_OIDC_CLIENT_ID')).'&redirect_uri='.urlencode(openid_connect_get_redirect_url()).'&scope='.rawurlencode(getDolGlobalString('MAIN_AUTHENTICATION_OIDC_SCOPES')).'&response_type=code&state='.urlencode(openid_connect_get_state());
56
57 return $url;
58}
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.