doc-locale/fr-fr/integration/oauth2_generic.md
{{< details >}}
{{< /details >}}
[!note] Si votre fournisseur prend en charge la spécification OpenID, vous devez utiliser
omniauth-openid-connectcomme fournisseur d'authentification.
Le gem omniauth-oauth2-generic permet l'authentification unique (SSO) entre GitLab et votre fournisseur OAuth 2.0, ou tout fournisseur OAuth 2.0 compatible avec ce gem.
Cette stratégie permet la configuration du processus SSO OmniAuth suivant :
Cette stratégie :
Pour configurer le fournisseur :
Enregistrez votre application auprès du fournisseur OAuth 2.0 avec lequel vous souhaitez vous authentifier.
L'URI de redirection que vous fournissez lors de l'enregistrement de l'application doit être :
http://your-gitlab.host.com/users/auth/oauth2_generic/callback
Vous devriez maintenant pouvoir obtenir un ID client et un secret client. L'emplacement de ces informations varie selon le fournisseur. Cela peut également être appelé ID d'application et secret d'application.
Sur votre serveur GitLab, effectuez les étapes suivantes.
{{< tabs >}}
{{< tab title="Paquet Linux (Omnibus)" >}}
Configurez les paramètres communs pour ajouter oauth2_generic comme fournisseur d'authentification unique. Cela active le provisionnement de compte Just-In-Time pour les utilisateurs qui n'ont pas de compte GitLab existant.
Modifiez /etc/gitlab/gitlab.rb pour ajouter la configuration de votre fournisseur. Par exemple :
gitlab_rails['omniauth_providers'] = [
{
name: "oauth2_generic",
label: "Provider name", # optional label for login button, defaults to "Oauth2 Generic"
app_id: "<your_app_client_id>",
app_secret: "<your_app_client_secret>",
args: {
client_options: {
site: "<your_auth_server_url>",
user_info_url: "/oauth2/v1/userinfo",
authorize_url: "/oauth2/v1/authorize",
token_url: "/oauth2/v1/token"
},
user_response_structure: {
root_path: [],
id_path: ["sub"],
attributes: {
email: "email",
name: "name"
}
},
authorize_params: {
scope: "openid profile email"
},
strategy_class: "OmniAuth::Strategies::OAuth2Generic"
}
}
]
Enregistrez le fichier et reconfigurez GitLab :
sudo gitlab-ctl reconfigure
{{< /tab >}}
{{< tab title="Chart Helm (Kubernetes)" >}}
Configurez les paramètres communs pour ajouter oauth2_generic comme fournisseur d'authentification unique. Cela active le provisionnement de compte Just-In-Time pour les utilisateurs qui n'ont pas de compte GitLab existant.
Exportez les valeurs Helm :
helm get values gitlab > gitlab_values.yaml
Placez le contenu suivant dans un fichier nommé oauth2_generic.yaml à utiliser comme Secret Kubernetes :
name: "oauth2_generic"
label: "Provider name" # optional label for login button defaults to "Oauth2 Generic"
app_id: "<your_app_client_id>"
app_secret: "<your_app_client_secret>"
args:
client_options:
site: "<your_auth_server_url>"
user_info_url: "/oauth2/v1/userinfo"
authorize_url: "/oauth2/v1/authorize"
token_url: "/oauth2/v1/token"
user_response_structure:
root_path: []
id_path: ["sub"]
attributes:
email: "email"
name: "name"
authorize_params:
scope: "openid profile email"
strategy_class: "OmniAuth::Strategies::OAuth2Generic"
Créez le Secret Kubernetes :
kubectl create secret generic -n <namespace> gitlab-oauth2-generic --from-file=provider=oauth2_generic.yaml
Modifiez gitlab_values.yaml et ajoutez la configuration du fournisseur :
global:
appConfig:
omniauth:
providers:
- secret: gitlab-oauth2-generic
Enregistrez le fichier et appliquez les nouvelles valeurs :
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
{{< /tab >}}
{{< tab title="Auto-compilée (source)" >}}
Configurez les paramètres communs pour ajouter oauth2_generic comme fournisseur d'authentification unique. Cela active le provisionnement de compte Just-In-Time pour les utilisateurs qui n'ont pas de compte GitLab existant.
Modifiez /home/git/gitlab/config/gitlab.yml :
production: &base
omniauth:
providers:
- { name: "oauth2_generic",
label: "Provider name", # optional label for login button, defaults to "Oauth2 Generic"
app_id: "<your_app_client_id>",
app_secret: "<your_app_client_secret>",
args: {
client_options: {
site: "<your_auth_server_url>",
user_info_url: "/oauth2/v1/userinfo",
authorize_url: "/oauth2/v1/authorize",
token_url: "/oauth2/v1/token"
},
user_response_structure: {
root_path: [],
id_path: ["sub"],
attributes: {
email: "email",
name: "name"
}
},
authorize_params: {
scope: "openid profile email"
},
strategy_class: "OmniAuth::Strategies::OAuth2Generic"
}
}
Enregistrez le fichier et redémarrez GitLab :
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
{{< /tab >}}
{{< /tabs >}}
Sur la page de connexion, une nouvelle icône devrait maintenant apparaître sous le formulaire de connexion habituel. Sélectionnez cette icône pour démarrer le processus d'authentification de votre fournisseur. Cela redirige le navigateur vers la page d'authentification de votre fournisseur OAuth 2.0. Si tout se passe bien, vous êtes redirigé vers votre instance GitLab et connecté.