2017-03-20 16:18:08 -04:00
|
|
|
/*
|
2018-03-08 06:09:50 -05:00
|
|
|
* Copyright 2002-2018 the original author or authors.
|
2017-03-20 16:18:08 -04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-05-01 12:01:41 -04:00
|
|
|
package sample.web;
|
2017-03-20 16:18:08 -04:00
|
|
|
|
2018-05-30 11:29:28 -04:00
|
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
2017-10-28 17:10:39 -04:00
|
|
|
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
|
2018-06-08 17:33:21 -04:00
|
|
|
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient;
|
2018-05-30 11:29:28 -04:00
|
|
|
import org.springframework.security.oauth2.core.user.OAuth2User;
|
2017-03-20 16:18:08 -04:00
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.ui.Model;
|
2018-03-08 06:09:50 -05:00
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
2017-03-20 16:18:08 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Joe Grandja
|
2018-05-25 09:37:28 -05:00
|
|
|
* @author Rob Winch
|
2017-03-20 16:18:08 -04:00
|
|
|
*/
|
|
|
|
@Controller
|
2018-03-08 06:09:50 -05:00
|
|
|
public class OAuth2LoginController {
|
2017-03-20 16:18:08 -04:00
|
|
|
|
2018-03-08 06:09:50 -05:00
|
|
|
@GetMapping("/")
|
2018-05-30 11:29:28 -04:00
|
|
|
public String index(Model model,
|
2018-06-08 17:33:21 -04:00
|
|
|
@RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient authorizedClient,
|
2018-05-30 11:29:28 -04:00
|
|
|
@AuthenticationPrincipal OAuth2User oauth2User) {
|
|
|
|
model.addAttribute("userName", oauth2User.getName());
|
2017-10-28 17:10:39 -04:00
|
|
|
model.addAttribute("clientName", authorizedClient.getClientRegistration().getClientName());
|
2018-05-30 11:29:28 -04:00
|
|
|
model.addAttribute("userAttributes", oauth2User.getAttributes());
|
2017-03-20 16:18:08 -04:00
|
|
|
return "index";
|
|
|
|
}
|
|
|
|
}
|