From 6b5adac14cf6ecd76ae5bdfc3b4e558efb283198 Mon Sep 17 00:00:00 2001 From: Josef Harte Date: Tue, 22 Nov 2022 16:14:25 +0000 Subject: [PATCH] fix: accept GitHub prop overrides --- .../config/model/v1/security/OAuth2.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/halyard-config/src/main/java/com/netflix/spinnaker/halyard/config/model/v1/security/OAuth2.java b/halyard-config/src/main/java/com/netflix/spinnaker/halyard/config/model/v1/security/OAuth2.java index 8183835fdc..e02d13cc49 100644 --- a/halyard-config/src/main/java/com/netflix/spinnaker/halyard/config/model/v1/security/OAuth2.java +++ b/halyard-config/src/main/java/com/netflix/spinnaker/halyard/config/model/v1/security/OAuth2.java @@ -78,16 +78,29 @@ public void setProvider(Provider provider) { newUserInfoMapping.setLastName("family_name"); break; case GITHUB: - newClient.setAccessTokenUri("https://github.com/login/oauth/access_token"); - newClient.setUserAuthorizationUri("https://github.com/login/oauth/authorize"); - newClient.setScope("user:email"); - - newResource.setUserInfoUri("https://api.github.com/user"); - - newUserInfoMapping.setEmail("email"); - newUserInfoMapping.setFirstName(""); - newUserInfoMapping.setLastName("name"); - newUserInfoMapping.setUsername("login"); + newClient.setAccessTokenUri( + isSet(client.getAccessTokenUri()) + ? client.getAccessTokenUri() + : "https://github.com/login/oauth/access_token"); + newClient.setUserAuthorizationUri( + isSet(client.getUserAuthorizationUri()) + ? client.getUserAuthorizationUri() + : "https://github.com/login/oauth/authorize"); + newClient.setScope(isSet(client.getScope()) ? client.getScope() : "user:email"); + + newResource.setUserInfoUri( + isSet(resource.getUserInfoUri()) + ? resource.getUserInfoUri() + : "https://api.github.com/user"); + + newUserInfoMapping.setEmail( + isSet(userInfoMapping.getEmail()) ? userInfoMapping.getEmail() : "email"); + newUserInfoMapping.setFirstName( + isSet(userInfoMapping.getFirstName()) ? userInfoMapping.getFirstName() : ""); + newUserInfoMapping.setLastName( + isSet(userInfoMapping.getLastName()) ? userInfoMapping.getLastName() : "name"); + newUserInfoMapping.setUsername( + isSet(userInfoMapping.getUsername()) ? userInfoMapping.getUsername() : "login"); break; case ORACLE: final String idcsBaseUrl = "https://idcs-${idcsTenantId}.identity.oraclecloud.com"; @@ -200,4 +213,8 @@ public static Provider fromString(String name) { + Arrays.toString(Provider.values())); } } + + private static boolean isSet(String config) { + return config != null; + } }