本文整理汇总了Java中org.springframework.security.oauth2.client.OAuth2RestTemplate.getAccessToken方法的典型用法代码示例。如果您正苦于以下问题:Java OAuth2RestTemplate.getAccessToken方法的具体用法?Java OAuth2RestTemplate.getAccessToken怎么用?Java OAuth2RestTemplate.getAccessToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.oauth2.client.OAuth2RestTemplate
的用法示例。
在下文中一共展示了OAuth2RestTemplate.getAccessToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAccessRootUrlWithOAuth2AccessToken
import org.springframework.security.oauth2.client.OAuth2RestTemplate; //导入方法依赖的package包/类
@Test
public void testAccessRootUrlWithOAuth2AccessToken() throws Exception {
final ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
resourceDetails.setClientId("myclient");
resourceDetails.setClientSecret("mysecret");
resourceDetails.setGrantType("client_credentials");
resourceDetails
.setAccessTokenUri("http://localhost:" + oAuth2ServerResource.getOauth2ServerPort() + "/oauth/token");
final OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails);
final OAuth2AccessToken accessToken = oAuth2RestTemplate.getAccessToken();
final String accessTokenAsString = accessToken.getValue();
localSkipperResource.getMockMvc().perform(get("/api").header("Authorization", "bearer " + accessTokenAsString))
.andDo(print()).andExpect(status().isOk());
}
示例2: testAccessAboutUrlWithOAuth2AccessToken
import org.springframework.security.oauth2.client.OAuth2RestTemplate; //导入方法依赖的package包/类
@Test
public void testAccessAboutUrlWithOAuth2AccessToken() throws Exception {
final ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
resourceDetails.setClientId("myclient");
resourceDetails.setClientSecret("mysecret");
resourceDetails.setGrantType("client_credentials");
resourceDetails
.setAccessTokenUri("http://localhost:" + oAuth2ServerResource.getOauth2ServerPort() + "/oauth/token");
final OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails);
final OAuth2AccessToken accessToken = oAuth2RestTemplate.getAccessToken();
final String accessTokenAsString = accessToken.getValue();
localSkipperResource.getMockMvc()
.perform(get("/api/about").header("Authorization", "bearer " + accessTokenAsString)).andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.versionInfo.server.name", is("Spring Cloud Skipper Server")))
.andExpect(jsonPath("$.versionInfo.server.version", notNullValue()));
}