Commit d7918b1a authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '17437' into 'master'

Optional custom icon in the OmniAuth login labels

Closes #17437

See merge request gitlab-org/gitlab!25744
parents b8b5b0f6 5801a770
......@@ -16,10 +16,18 @@ module AuthHelper
Gitlab::Auth.omniauth_enabled?
end
def provider_has_icon?(name)
def provider_has_custom_icon?(name)
icon_for_provider(name.to_s)
end
def provider_has_builtin_icon?(name)
PROVIDERS_WITH_ICONS.include?(name.to_s)
end
def provider_has_icon?(name)
provider_has_builtin_icon?(name) || provider_has_custom_icon?(name)
end
def qa_class_for_provider(provider)
{
saml: 'qa-saml-login-button',
......@@ -35,6 +43,10 @@ module AuthHelper
Gitlab::Auth::OAuth::Provider.label_for(name)
end
def icon_for_provider(name)
Gitlab::Auth::OAuth::Provider.icon_for(name)
end
def form_based_provider_priority
['crowd', /^ldap/, 'kerberos']
end
......@@ -109,7 +121,9 @@ module AuthHelper
def provider_image_tag(provider, size = 64)
label = label_for_provider(provider)
if provider_has_icon?(provider)
if provider_has_custom_icon?(provider)
image_tag(icon_for_provider(provider), alt: label, title: "Sign in with #{label}")
elsif provider_has_builtin_icon?(provider)
file_name = "#{provider.to_s.split('_').first}_#{size}.png"
image_tag("auth_buttons/#{file_name}", alt: label, title: "Sign in with #{label}")
......
---
title: Optional custom icon in the OmniAuth login labels
merge_request: 25744
author: Tobias Wawryniuk, Luca Leonardo Scorcia
type: added
......@@ -34,6 +34,7 @@ The OpenID Connect will provide you with a client details and secret for you to
gitlab_rails['omniauth_providers'] = [
{ 'name' => 'openid_connect',
'label' => '<your_oidc_label>',
'icon' => '<custom_provider_icon>',
'args' => {
'name' => 'openid_connect',
'scope' => ['openid','profile'],
......@@ -58,6 +59,7 @@ The OpenID Connect will provide you with a client details and secret for you to
```yaml
- { name: 'openid_connect',
label: '<your_oidc_label>',
icon: '<custom_provider_icon>',
args: {
name: 'openid_connect',
scope: ['openid','profile'],
......@@ -82,6 +84,8 @@ The OpenID Connect will provide you with a client details and secret for you to
1. For the configuration above, change the values for the provider to match your OpenID Connect client setup. Use the following as a guide:
- `<your_oidc_label>` is the label that will be displayed on the login page.
- `<custom_provider_icon>` (optional) is the icon that will be displayed on the login page. Icons for the major social login platforms are built-in into GitLab,
but can be overridden by specifying this parameter. Both local paths and absolute URLs are accepted.
- `<your_oidc_url>` (optional) is the URL that points to the OpenID Connect provider. For example, `https://example.com/auth/realms/your-realm`.
If this value is not provided, the URL is constructed from the `client_options` in the following format: `<client_options.scheme>://<client_options.host>:<client_options.port>`.
- If `discovery` is set to `true`, the OpenID Connect provider will try to auto discover the client options using `<your_oidc_url>/.well-known/openid-configuration`. Defaults to `false`.
......
......@@ -75,6 +75,12 @@ module Gitlab
config = config_for(name)
(config && config['label']) || LABELS[name] || name.titleize
end
def self.icon_for(name)
name = name.to_s
config = config_for(name)
config && config['icon']
end
end
end
end
......
......@@ -154,4 +154,34 @@ describe AuthHelper do
expect(helper.unlink_provider_allowed?(provider)).to eq 'policy_unlink_result'
end
end
describe '#provider_has_icon?' do
it 'returns true for defined providers' do
expect(helper.provider_has_icon?(described_class::PROVIDERS_WITH_ICONS.sample)).to eq true
end
it 'returns false for undefined providers' do
expect(helper.provider_has_icon?('test')).to be_falsey
end
context 'when provider is defined by config' do
before do
allow(Gitlab::Auth::OAuth::Provider).to receive(:icon_for).with('test').and_return('icon')
end
it 'returns true' do
expect(helper.provider_has_icon?('test')).to be_truthy
end
end
context 'when provider is not defined by config' do
before do
allow(Gitlab::Auth::OAuth::Provider).to receive(:icon_for).with('test').and_return(nil)
end
it 'returns true' do
expect(helper.provider_has_icon?('test')).to be_falsey
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment