From baa3b6f25836b4ae71fa2f5d87ccc496d63bf159 Mon Sep 17 00:00:00 2001 From: Joe Grandja Date: Wed, 20 Sep 2017 22:44:13 -0400 Subject: [PATCH] Add utility for loading properties of client types Fixes gh-4560 --- .../client/OAuth2ClientPropertiesUtil.java | 51 +++++++++++++++++++ ...ng-security-oauth2-client-types.properties | 44 ++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 config/src/main/java/org/springframework/security/config/oauth2/client/OAuth2ClientPropertiesUtil.java create mode 100644 config/src/main/resources/org/springframework/security/config/oauth2/client/spring-security-oauth2-client-types.properties diff --git a/config/src/main/java/org/springframework/security/config/oauth2/client/OAuth2ClientPropertiesUtil.java b/config/src/main/java/org/springframework/security/config/oauth2/client/OAuth2ClientPropertiesUtil.java new file mode 100644 index 0000000000..7a1733e538 --- /dev/null +++ b/config/src/main/java/org/springframework/security/config/oauth2/client/OAuth2ClientPropertiesUtil.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.security.config.oauth2.client; + +import org.springframework.core.env.PropertiesPropertySource; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.support.ResourcePropertySource; + +import java.io.IOException; + +/** + * Utility methods for OAuth 2.0 client properties. + * + * @author Joe Grandja + * @since 5.0.0 + */ +public final class OAuth2ClientPropertiesUtil { + + public static final String CLIENT_TYPES_PROPERTY_PREFIX = "spring.security.oauth2.client.client-types"; + + private static final String CLIENT_TYPES_RESOURCE_LOCATION = "spring-security-oauth2-client-types.properties"; + + private OAuth2ClientPropertiesUtil() { + } + + public static PropertiesPropertySource loadClientTypesPropertySource() { + try { + return new ResourcePropertySource( + new ClassPathResource(CLIENT_TYPES_RESOURCE_LOCATION, OAuth2ClientPropertiesUtil.class)); + } + catch (IOException ioe) { + throw new RuntimeException("Failed to load OAuth 2.0 client types resource: " + + CLIENT_TYPES_RESOURCE_LOCATION, ioe); + } + } +} + diff --git a/config/src/main/resources/org/springframework/security/config/oauth2/client/spring-security-oauth2-client-types.properties b/config/src/main/resources/org/springframework/security/config/oauth2/client/spring-security-oauth2-client-types.properties new file mode 100644 index 0000000000..1447daa32e --- /dev/null +++ b/config/src/main/resources/org/springframework/security/config/oauth2/client/spring-security-oauth2-client-types.properties @@ -0,0 +1,44 @@ +# Google +spring.security.oauth2.client.client-types.google.client-authentication-method=basic +spring.security.oauth2.client.client-types.google.authorization-grant-type=authorization_code +spring.security.oauth2.client.client-types.google.redirect-uri={scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{clientAlias} +spring.security.oauth2.client.client-types.google.scope=openid, profile, email, address, phone +spring.security.oauth2.client.client-types.google.authorization-uri=https://accounts.google.com/o/oauth2/v2/auth +spring.security.oauth2.client.client-types.google.token-uri=https://www.googleapis.com/oauth2/v4/token +spring.security.oauth2.client.client-types.google.user-info-uri=https://www.googleapis.com/oauth2/v3/userinfo +spring.security.oauth2.client.client-types.google.jwk-set-uri=https://www.googleapis.com/oauth2/v3/certs +spring.security.oauth2.client.client-types.google.client-name=Google +spring.security.oauth2.client.client-types.google.client-alias=google + +# GitHub +spring.security.oauth2.client.client-types.github.client-authentication-method=basic +spring.security.oauth2.client.client-types.github.authorization-grant-type=authorization_code +spring.security.oauth2.client.client-types.github.redirect-uri={scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{clientAlias} +spring.security.oauth2.client.client-types.github.scope=user +spring.security.oauth2.client.client-types.github.authorization-uri=https://github.com/login/oauth/authorize +spring.security.oauth2.client.client-types.github.token-uri=https://github.com/login/oauth/access_token +spring.security.oauth2.client.client-types.github.user-info-uri=https://api.github.com/user +spring.security.oauth2.client.client-types.github.user-name-attribute-name=name +spring.security.oauth2.client.client-types.github.client-name=GitHub +spring.security.oauth2.client.client-types.github.client-alias=github + +# Facebook +spring.security.oauth2.client.client-types.facebook.client-authentication-method=post +spring.security.oauth2.client.client-types.facebook.authorization-grant-type=authorization_code +spring.security.oauth2.client.client-types.facebook.redirect-uri={scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{clientAlias} +spring.security.oauth2.client.client-types.facebook.scope=public_profile, email +spring.security.oauth2.client.client-types.facebook.authorization-uri=https://www.facebook.com/v2.8/dialog/oauth +spring.security.oauth2.client.client-types.facebook.token-uri=https://graph.facebook.com/v2.8/oauth/access_token +spring.security.oauth2.client.client-types.facebook.user-info-uri=https://graph.facebook.com/me +spring.security.oauth2.client.client-types.facebook.user-name-attribute-name=name +spring.security.oauth2.client.client-types.facebook.client-name=Facebook +spring.security.oauth2.client.client-types.facebook.client-alias=facebook + +# Okta +spring.security.oauth2.client.client-types.okta.client-authentication-method=basic +spring.security.oauth2.client.client-types.okta.authorization-grant-type=authorization_code +spring.security.oauth2.client.client-types.okta.redirect-uri={scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{clientAlias} +spring.security.oauth2.client.client-types.okta.scope=openid, profile, email, address, phone +spring.security.oauth2.client.client-types.okta.client-name=Okta +spring.security.oauth2.client.client-types.okta.client-alias=okta +