我已经关注了Web: Getting Started Samples。当函数AdobeCreativeSDK.init
被调用时,它首先使用请求方法OPTIONS调用https://adobeid-na1.services.adobe.com/ims/check/v4/token
,然后使用请求方法POST调用,两者都返回状态代码200 OK。对POST请求的响应返回{"error":"invalid_credentials"}
,我不知道为什么以及如何解决这个问题。
任何帮助将不胜感激。
答案 0 :(得分:5)
你在控制台中看到这样的东西吗?
XMLHttpRequest无法加载https://adobeid-na1.services.adobe.com/ims/check/v4/token。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许原点“https://your.domain.com”访问。
然后您可能没有有效的SSL证书。
来自Adobe的Getting started with the Creative SDK for Web:
如果由于而导致XMLHttpRequest错误 'Access-Control-Allow-Origin',您的SSL可能存在问题 设置(如本指南的“先决条件”部分所述,SSL是 必需的)。
以下是先决条件部分[强调添加]中所述的内容:
<强>先决条件强>
在使用Creative SDK之前,您必须先注册 应用程序并获取客户端ID(API密钥)和客户端密钥值。对于 有关详细信息,请参阅本指南的“注册您的应用程序”部分。
- 醇>
需要以下软件:
- 支持的浏览器:Chrome 53 +,Safari 9 +,Firefox 45 +,Edge,IE11 +
- 需要SSL:您的网站必须在集成Creative SDK的任何页面上支持SSL。
如果您正在使用localhost
对您的开发计算机进行测试,那么您需要修改hosts
文件并设置自己的域映射到127.0.0.1,然后您需要在您的服务器上配置自签名证书。
你可能还想看看How to use locally(来自他们的Github回购),这个有着这个美妙的宝石:
openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
有用的资源:
以下是我在Adobe I / O上配置测试应用程序的方法:
在根目录下,要创建自签名证书,请运行:
openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
然后,我设置了一个简单的python服务器,它使用上面创建的自签名证书server.pem
:
# ./start.py
import BaseHTTPServer, SimpleHTTPServer
import ssl
httpd = BaseHTTPServer.HTTPServer(('localhost', 4443), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='server.pem', server_side=True)
httpd.serve_forever()
启动我的服务器
python ./start.py
重要提示:您将在第二次通话时获得以下有效负载的200响应:{"error":"invalid_credentials"}
。只要您没有收到控制台错误,您的网络应用就准备好了。
根据文档,我添加了一个带csdk-login
的按钮来测试User Auth UI api。
文件结构:
/app
├── config.js <-- my clientId config
├── index.html
├── index.js
├── server.pem <-- my self-signed cert
└── start.py <-- my server
<强> HTML:强>
<!DOCTYPE html>
<html>
<head>
<title>Technophobia: SDK Getting Started</title>
</head>
<body>
<h1>Adobe Creative SDK</h1>
<p>Look at the console</p>
<button id="csdk-login">Log in to Creative Cloud</button>
<script type="text/javascript" src="https://cdn-creativesdk.adobe.io/v1/csdk.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript" src="index.js"></script>
</body>
</html>
<强> JS:强>
/* 1) Initialize the AdobeCreativeSDK object */
AdobeCreativeSDK.init({
/* 2) Add your Client ID (API Key) */
clientID: CONFIG.CSDK_CLIENT_ID, //
API: ["Asset"],
onError: function(error) {
/* 3) Handle any global or config errors */
if (error.type === AdobeCreativeSDK.ErrorTypes.AUTHENTICATION) {
console.log('You must be logged in to use the Creative SDK');
} else if (error.type === AdobeCreativeSDK.ErrorTypes.GLOBAL_CONFIGURATION) {
console.log('Please check your configuration');
} else if (error.type === AdobeCreativeSDK.ErrorTypes.SERVER_ERROR) {
console.log('Oops, something went wrong');
}
}
});
/* 1) Add a click handler to a button that calls a helper function */
document.getElementById("csdk-login").addEventListener('click', handleCsdkLogin, false);
/* 2) Make a helper function */
function handleCsdkLogin() {
/* 3) Get auth status */
AdobeCreativeSDK.getAuthStatus(function(csdkAuth) {
/* 4) Handle auth based on status */
if (csdkAuth.isAuthorized) {
// The user is logged in and has authorized your site.
console.log('Logged in!');
} else {
// Trigger a login
AdobeCreativeSDK.login(handleCsdkLogin);
}
});
}