gpt4 book ai didi

java - 在 Java 中生成 OAuth 签名

转载 作者:太空宇宙 更新时间:2023-11-04 13:58:56 25 4
gpt4 key购买 nike

我正在开发 java web 应用程序,现在我正在尝试使用 QTIWorks 连接我的网站

我有消费者 key 和 secret ,我需要生成 OAuth 签名以通过 LTI 与 QTIWorks 连接

<html>

<head> </head>

<body>
<form action="https://webapps.ph.ed.ac.uk/qtiworks-dev2/lti/domainlaunch" name="ltiLaunchForm" id="ltiLaunchForm" method="post" target="basicltiLaunchFrame" enctype="application/x-www-form-urlencoded" style="display: block;">
<input type="hidden" name="context_id" value="cid-00113">
<input type="hidden" name="context_label" value="SI106">
<input type="hidden" name="context_title" value="Design of Personal Environments 1">
<input type="hidden" name="ext_note" value="Instructor from first course">
<input type="hidden" name="launch_presentation_locale" value="en_us">
<input type="hidden" name="lis_person_contact_email_primary" value="sian@imscert.org">
<input type="hidden" name="lis_person_name_family" value="Instructor">
<input type="hidden" name="lis_person_name_given" value="Siân">
<input type="hidden" name="lis_person_sourcedid" value="school.edu:user">
<input type="hidden" name="resource_link_description" value="This learning space is private">
<input type="hidden" name="resource_link_id" value="res-0012612">
<input type="hidden" name="resource_link_title" value="My Weekly Wiki">
<input type="hidden" name="roles" value="Instructor">
<input type="hidden" name="tool_consumer_info_product_family_code" value="sakai-unit">
<input type="hidden" name="tool_consumer_info_version" value="0.9">
<input type="hidden" name="tool_consumer_instance_description" value="University of School (LMSng)">
<input type="hidden" name="tool_consumer_instance_guid" value="lmsng.school.edu">
<input type="hidden" name="user_id" value="user-0016">
<input type="hidden" name="oauth_callback" value="about:blank">
<input type="hidden" name="lis_outcome_service_url" value="....">
<input type="hidden" name="lis_result_sourcedid" value="{&quot;zap&quot; : &quot;Siân JSON 1234 Sourcedid <>&amp;lt;&quot;}">
<input type="hidden" name="custom_simple_key" value="custom_simple_value">
<input type="hidden" name="custom_complex____________key" value="Complex!@#$^*(){}[]½Value">
<input type="hidden" name="lti_version" value="LTI-1p0">
<input type="hidden" name="lti_message_type" value="basic-lti-launch-request">
<input type="submit" name="ext_submit" value="Finish Launch">
<input type="hidden" name="oauth_version" value="1.0">
<input type="hidden" name="oauth_nonce" value="505005bff1c2cf2e1750ed914e489a9b">
<input type="hidden" name="oauth_timestamp" value="1427022367">
<input type="hidden" name="oauth_consumer_key" value="my consumer key">
<input type="hidden" name="oauth_signature_method" value="HMAC-SHA1">
<input type="hidden" name="oauth_signature" value="I need generate this value">
<input type="hidden" name="ext_submit" value="Finish Launch">
<input type="submit" name="submit" value="submit"></form>


<iframe name="basicltiLaunchFrame" id="basicltiLaunchFrame" src="" width="100%" height="900" scrolling="auto" frameborder="1" transparency="">

</iframe>
</body>

我需要在这一行生成 OAuth 签名

<input type="hidden" name="oauth_signature" value="I need generate this value">

我怎样才能做到这一点?

最佳答案

用 JavaScript 来做:

document.getElementById("oauth_signature").value = "Value you want to generate";

编辑:

您可以使用加密算法库(例如 https://code.google.com/p/crypto-js/ )来计算 oauth 签名:

var key = document.getElementById("oauth_consumer_key").value
var hash = CryptoJS.SHA1(key);
document.getElementById("oauth_signature").value = hash

根据oauth_signature_method的值,您应该使用适当的加密算法。

switch(document.getElementById("oauth_signature_method").value) {
case "HMAC-SHA1":
var hash = CryptoJS.SHA1(key)
break;
case "HMAC-SHA-2":
var hash = CryptoJS.SHA256(key)
break;
case ...
}

关于java - 在 Java 中生成 OAuth 签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29508268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com