本文整理匯總了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()));
}