diff --git a/src/main/webapp/html/rpttokenreader/view.jsp b/src/main/webapp/html/rpttokenreader/view.jsp index 3ab8b29..345860d 100644 --- a/src/main/webapp/html/rpttokenreader/view.jsp +++ b/src/main/webapp/html/rpttokenreader/view.jsp @@ -37,9 +37,13 @@ pageContext.setAttribute("userContexts", userContexts); function initForm() { $('#response_group').hide(); $('#error_msg').hide(); - $('#rawTokenResult').hide(); + openInfo('intro_info') + closeInfo('token_info') + closeInfo('refresh_token_info') + closeInfo('refresh') + console.log("hided response_group") } @@ -57,8 +61,6 @@ pageContext.setAttribute("userContexts", userContexts); $('#refresh_token_url').html(''); $('#client_id').html(''); - - } function setResults(resultObject) { @@ -71,7 +73,8 @@ pageContext.setAttribute("userContexts", userContexts); $('#refresh_token_url').text(resultObject.token_url); $('#client_id').text(resultObject.client_id); - $('#refresh_usage_info').html(generateRefreshCurl("[CLIENT_ID]", "[REFRESH_TOKEN]", "[REFRESH_URL]")) + $('#usage_token').html(generateAccessCurl("[REFRESH_TOKEN]", "[SERVICE_URL]")) + $('#usage_refresh').html(generateRefreshCurl("[CLIENT_ID]", "[REFRESH_TOKEN]", "[REFRESH_URL]")) var raw = JSON.parse(resultObject.raw_token) @@ -95,6 +98,10 @@ pageContext.setAttribute("userContexts", userContexts); $('#response_group').show(); console.log("resultObject", resultObject) + + closeInfo('intro_info', false); + openInfo('token_info', true); + openInfo('refresh_token_info', true); } function setError(error_comment) { @@ -142,10 +149,19 @@ pageContext.setAttribute("userContexts", userContexts); }); } - function toggleInfo(destination_id) { - $("#" + destination_id).toggle(); - } + function openInfo(destination_id) { + toggleInfo(destination_id, true) + } + function closeInfo(destination_id, do_switch) { + toggleInfo(destination_id, false) + } + function toggleInfo(destination_id, do_switch) { + $("#" + destination_id).toggle(do_switch); + do_switch = $("#" + destination_id).css('display') != 'none'; + $("#" + destination_id + "_icon").toggleClass("icon-chevron-up", !do_switch); + $("#" + destination_id + "_icon").toggleClass("icon-chevron-down", do_switch); + } function decodeFunction(text_id) { var decode_text = $("#" + text_id).val(); @@ -154,10 +170,19 @@ pageContext.setAttribute("userContexts", userContexts); '_blank' ); } + + + + + function generateAccessCurl(token, service_url) { + return "curl -X GET -H 'Authorization: Bearer " + token + "' \\\n" + + "\t " + service_url + } + function generateRefreshCurl(client_id, refresh_token, refresh_url) { - return "curl --location '" + refresh_url + "' \\\n" + - "\t--header 'Content-Type: application/x-www-form-urlencoded' \\\n" + + return "curl -X POST --location '" + refresh_url + "' \\\n" + + // "\t--header 'Content-Type: application/x-www-form-urlencoded' \\\n" + "\t--data-urlencode 'grant_type=refresh_token' \\\n" + "\t--data-urlencode 'client_id=" + client_id + "' \\\n" + "\t--data-urlencode 'refresh_token=" + refresh_token + "' " @@ -178,7 +203,38 @@ pageContext.setAttribute("userContexts", userContexts); document.addEventListener("copy", listener); document.execCommand("copy"); document.removeEventListener("copy", listener); + + + navigator.clipboard.writeText(text).then(function () { + /* clipboard successfully set */ + }, function () { + /* clipboard write failed */ + }); } + + function copyAccessCurl() { + + // ***.dev.d4science.org => api.dev.d4science.org + // ***.pre.d4science.org => api.pre.d4science.org + // xxx.d4science.org => api.d4science.org + + var client_id = global_token_response.client_id; + var service_path = "api.d4science.org"; + + if (client_id.endsWith("dev.d4science.org")){ + service_path = "api.dev.d4science.org"; + } else if (client_id.endsWith("pre.d4science.org")){ + service_path = "api.pre.d4science.org"; + } + + var curl = generateAccessCurl( + global_token_response.access_token, + "https://" + service_path + "/catalogue/items"); + copyText(curl); + } + + + function copyRefreshCurl() { var curl = generateRefreshCurl( global_token_response.client_id, @@ -188,7 +244,7 @@ pageContext.setAttribute("userContexts", userContexts); copyText(curl); } - function copyFunction(text_id) { + function copyFromTextField(text_id) { /* Get the text field */ var copyText = document.getElementById(text_id); @@ -233,33 +289,52 @@ pageContext.setAttribute("userContexts", userContexts); class="btn btn-primary" onClick="getUMAToken('${resourceURL}')">Get Token - + + +
-
- Obtain your personal OAuth2 Access and Refresh Tokens, to be used for - programmatic - interaction with the services. -
Do not use this token to authenticate services but only for personal access +
+
+ Instructions + +
+
+

Obtain your personal OAuth2 Access and Refresh Tokens, to be used for + programmatic interaction with the D4Science Resources

+

Do not use this token to authenticate services but only for personal + access +

+

+ ref: +

+

-
+ +
-
OAuth Access Token (Bearer Authorization) -
-
- +
@@ -268,38 +343,51 @@ pageContext.setAttribute("userContexts", userContexts); + onclick="copyFromTextField('tokenResult')" title="Copy" alt="Copy"> + +
- -
+
-
Oauth2 Refresh Token -
+ Oauth2 Refresh Token
- +
@@ -309,57 +397,73 @@ pageContext.setAttribute("userContexts", userContexts); - +
- -
-
Refresh parameters
- +
+
+ Refresh parameters + +
+
- refresh token url: - +
+ refresh token url: +
- client_id:
+ client_id:
- curl refresh request (copy): + generate curl refresh request:
+
- You can decode the tokens using https://jwt.io/ + You can decode the tokens using https://jwt.io/