<!DOCTYPE html> <html lang="en"> <head> <title>Callback Handler</title> <script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script> </head> <body> <h1> Received Authorization Code </h1> <div id="container">Waiting for results</div> <Br/> <p> Access token: <span id="access-token"></span> </p> <script type="text/javascript"> var params = paramObj(); var p4oauthToken = "https://{{p4oAuthHostname}}:{{p4oAuthPort}}/grants/token"; $(function() { if (!!params.code) { getAccessToken(); } else if (!!params.token) { listFiles(params.token); } }); function getAccessToken() { var requestParams = { client_id: "jdoe", code: params.code, redirect_uri: "{{redirectUri}}", grant_type: "authorization_code" }; $.ajax({ type: "POST", url: p4oauthToken, data: requestParams, success: tokenComplete, dataType: "json" }).fail(showError); } /** * @param data Should contain both the URI token and the P4D token * @param textStatus * @param jqXHR */ function tokenComplete(data, textStatus, jqXHR){ listFiles(data.perforce_token); $("#access-token").text(data.access_token); } function listFiles(perforceToken) { var listUrl = "https://{{hostname}}:8444/list"; var params = { client_id: "jdoe", token: perforceToken }; $.ajax({ type: "POST", url: listUrl, data: params, success: listComplete, dataType: "json" }).fail(showError); } /** * We've successfully listed * @param data */ function listComplete(data) { var html = "<div id='results'>"; for (var idx = 0; idx < data.length; idx++) { html += "<p>" + data[idx] + "</p>"; } html += "</div>"; $("#container").html(html); } function showError() { $("#container").html("<em>Failed</em>"); } function paramObj() { var searchStr = window.location.search; if (!searchStr) return; if ( searchStr.indexOf("?") === 0 ) searchStr = searchStr.substring(1); var obj = {}; if ( searchStr.length > 0) { var splits = searchStr.split("&"); for (var idx = 0; idx < splits.length; ++idx) { var kvArr = splits[idx].split("="); obj[decodeURIComponent(kvArr[0])] = decodeURIComponent(kvArr[1]); } } return obj; } </script> </body> </html>
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 9180 | tjuricek |
0.1.1 Adding mechanism for fetching the p4 token given the bearer token on an Authorization header. This is probably secure since we can't use these tokens except for the restricted hosts. |
||
#2 | 9157 | tjuricek | Added basic "authorization code" workflow test. | ||
#1 | 9138 | tjuricek |
Added a "test server" with startTestServer and stopTestServer gradle tasks. The test server isn't 100% complete, but the gradle tasks should be. This is to be used to drive tests forward via a web browser. |