为了跟进 Yuci,我创建了一个 Spring 和 Spring Boot 集成示例的存储库。有些只需要配置。ORCID 最近发布了 OpenID Connect 和隐式 OAuth 功能,您现在还可以使用少量 javascript 进行客户端身份验证。
ORCID 端的更改意味着 Spring boot 只需要以下内容:
@SpringBootApplication
@EnableOAuth2Sso
@Controller
public class ReallySimpleOrcidOauthApplication {
@RequestMapping("/")
@ResponseBody
public final String home() {
return "Welcome, " + SecurityContextHolder.getContext().getAuthentication().getName();
}
public static void main(String[] args) {
SpringApplication application = new SpringApplication(ReallySimpleOrcidOauthApplication.class);
Properties properties = new Properties();
properties.put("security.oauth2.client.clientId", "XXX");
properties.put("security.oauth2.client.clientSecret", "XXX");
properties.put("security.oauth2.client.accessTokenUri", "https://sandbox.orcid.org/oauth/token");
properties.put("security.oauth2.client.userAuthorizationUri", "https://sandbox.orcid.org/oauth/authorize");
properties.put("security.oauth2.client.tokenName", "access_token");
properties.put("security.oauth2.client.scope", "openid");
properties.put("security.oauth2.resource.userInfoUri", "https://sandbox.orcid.org/oauth/userinfo");
application.setDefaultProperties(properties);
application.run(args);
}
}
还有一个使用 JWT 的仅客户端隐式流的示例。这个以及更多 ORCID OAuth 和 OpenID 连接示例可以在 github上找到