client, jsp -> html , test flow

pull/4/head
shengzhaoli.shengz 2023-10-16 19:47:36 +08:00
parent 738ea0a09e
commit b7ca59883c
2 changed files with 183 additions and 0 deletions

View File

@ -222,6 +222,20 @@ public class OauthClientDetailsDto implements Serializable {
return this.authorizationGrantTypes.contains("refresh_token");
}
/**
* @since 3.0.0
*/
public boolean isContainsDeviceCode() {
return this.authorizationGrantTypes.contains("device_code");
}
/**
* @since 3.0.0
*/
public boolean isContainsJwtBearer() {
return this.authorizationGrantTypes.contains("jwt-bearer");
}
public OauthClientDetails createDomain() {
OauthClientDetails clientDetails = new OauthClientDetails()

View File

@ -0,0 +1,169 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,user-scalable=no"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<link rel="shortcut icon" href="../../static/favicon.ico" th:href="@{/favicon.ico}"/>
<title>Test [[${clientDetailsDto.clientId}]] - Spring Security&OAuth2.1</title>
<th:block th:insert="~{fragments/main::header-css}"/>
<script th:src="@{/angular.min.js}" src="../../static/angular.min.js"></script>
</head>
<body class="container">
<div ng-app>
<a th:href="@{/}">Home</a>
<h2>Test [[${clientDetailsDto.clientId}]]</h2>
<p>
针对不同的<code>grant_type</code>提供不同的测试URL,
完整的OAuth测试请访问<a href="https://gitee.com/mkk/spring-oauth-client" target="_blank">spring-oauth-client</a>项目.
</p>
<div ng-controller="TestClientCtrl">
<div class="well well-sm">
请先输入client_secret: <input type="text" value="" placeholder="client_secret" ng-model="clientSecret"
size="100" required="required"/>
</div>
<hr/>
<div th:if="${clientDetailsDto.containsAuthorizationCode}" class="panel panel-default">
<div class="panel-heading">Test [authorization_code]</div>
<div class="panel-body">
<p class="text-muted">输入每一步必要的信息后点击其下面的链接地址.</p>
<ol>
<li>
<p>
<code>从 spring-oauth-server获取 'code'</code>
<br/>
redirect_uri: <input type="text" value="" ng-model="redirectUri" size="70"
required="required"/>
<br/>
<a href="${contextPath}/oauth/authorize?client_id={{clientId}}&redirect_uri={{redirectUri}}&response_type=code&scope={{scope}}"
target="_blank">
/oauth/authorize?client_id={{clientId}}&redirect_uri={{redirectUri}}&response_type=code&scope={{scope}}</a>
<span class="label label-info">GET</span>
</p>
</li>
<li>
<code>用 'code' 换取 'access_token'</code>
<br/>
输入第一步获取的code: <input type="text" name="code" value="" ng-model="code"
required="required"/>
<br/>
<form action="${contextPath}/oauth/token?client_id={{clientId}}&client_secret={{clientSecret}}&grant_type=authorization_code&code={{code}}&redirect_uri={{redirectUri}}"
method="post" target="_blank">
<button class="btn btn-link" type="submit">
/oauth/token?client_id={{clientId}}&client_secret={{clientSecret}}&grant_type=authorization_code&code={{code}}&redirect_uri={{redirectUri}}
</button>
<span class="label label-warning">POST</span>
</form>
</li>
</ol>
</div>
</div>
<div th:if="${clientDetailsDto.containsPassword}" class="panel panel-default">
<div class="panel-heading">Test [password]</div>
<div class="panel-body">
<p class="text-muted">输入username, password 后点击链接地址.</p>
username: <input type="text" required="required" ng-model="username"/>
<br/>
password: <input type="text" required="required" ng-model="password"/>
<br/>
<form action="${contextPath}/oauth/token?client_id={{clientId}}&client_secret={{clientSecret}}&grant_type=password&scope={{scope}}&username={{username}}&password={{password}}"
method="post" target="_blank">
<button class="btn btn-link" type="submit">
/oauth/token?client_id={{clientId}}&client_secret={{clientSecret}}&grant_type=password&scope={{scope}}&username={{username}}&password={{password}}
</button>
<span class="label label-warning">POST</span>
</form>
</div>
</div>
<div th:if="${clientDetailsDto.containsDeviceCode}" class="panel panel-default">
<div class="panel-heading">Test [device_code]</div>
<div class="panel-body">
<p class="text-muted">输入redirect_uri 后点击链接地址. 获取access_token后注意查看redirect_uri的hash部分(#号后边部分)</p>
redirect_uri: <input type="text" value="" ng-model="implicitRedirectUri" size="70"
required="required"/>
<p>
<a href="${contextPath}/oauth/authorize?client_id={{clientId}}&client_secret={{clientSecret}}&response_type=token&scope={{scope}}&redirect_uri={{implicitRedirectUri}}"
target="_blank"
>/oauth/authorize?client_id={{clientId}}&client_secret={{clientSecret}}&response_type=token&scope={{scope}}&redirect_uri={{implicitRedirectUri}}</a>
<span class="label label-info">GET</span>
</p>
</div>
</div>
<div th:if="${clientDetailsDto.containsClientCredentials}" class="panel panel-default">
<div class="panel-heading">Test [client_credentials]</div>
<div class="panel-body">
<p class="text-muted">点击链接地址即可测试</p>
<form action="${contextPath}/oauth/token?client_id={{clientId}}&client_secret={{clientSecret}}&grant_type=client_credentials&scope={{scope}}"
method="post" target="_blank">
<button class="btn btn-link" type="submit">
/oauth/token?client_id={{clientId}}&client_secret={{clientSecret}}&grant_type=client_credentials&scope={{scope}}
</button>
<span class="label label-warning">POST</span>
</form>
</div>
</div>
<div th:if="${clientDetailsDto.containsRefreshToken}" class="panel panel-default">
<div class="panel-heading">Test [refresh_token]</div>
<div class="panel-body">
<p class="text-muted">输入refresh_token 后点击链接地址.</p>
refresh_token: <input type="text" ng-model="refreshToken" required="required" size="70"/>
<br/>
<form action="${contextPath}/oauth/token?client_id={{clientId}}&client_secret={{clientSecret}}&grant_type=refresh_token&refresh_token={{refreshToken}}"
method="post" target="_blank">
<button class="btn btn-link" type="submit">
/oauth/token?client_id={{clientId}}&client_secret={{clientSecret}}&grant_type=refresh_token&refresh_token={{refreshToken}}
</button>
<span class="label label-warning">POST</span>
</form>
</div>
</div>
<div class="text-center">
<a th:href="@{/client_details}" class="btn btn-default">Back</a>
</div>
</div>
</div>
<script th:inline="javascript">
var TestClientCtrl = ["$scope", function ($scope) {
$scope.clientId = [[${clientDetailsDto.clientId}]];
$scope.clientSecret = "";
$scope.scope = [[${clientDetailsDto.scopes}]];
var emptyRedirectUri = [[${empty clientDetailsDto.redirectUris}]];
if (emptyRedirectUri) {
// $scope.implicitRedirectUri = location.href;
$scope.redirectUri = "http://localhost:8080/unity/dashboard";
} else {
// $scope.implicitRedirectUri = "${clientDetailsDto.webServerRedirectUri}";
$scope.redirectUri = [[${clientDetailsDto.redirectUris}]];
}
$scope.username = "mobile";
$scope.password = "mobile";
//a temp value
$scope.refreshToken = "xYCsaPu7YV_hB6TfLbWsFBws1YvP7D_qAJFlSCvT5u-RbP6uMwEudHZaVnoyw3wuaXO-8F3t_GY";
}];
</script>
<div th:replace="~{fragments/main :: footer}"/>
</body>
</html>