续期步骤
获得一个开发者 access_token
- 注册账号
- 创建一个photoshop api项目
- 下载
config.zip
文件(创建时下载)
获得文件
- private.key - 关键文件
- certificate_pub.crt
提取项目的相关key
- clientID
- clientSecret
- technicalAccountId
- orgId
- metaScopes ?不知道是啥
ent_ccas_sdk
自动续期
node
- 安装依赖
npm -S @adobe/jwt-auth
import auth from "@adobe/jwt-auth";
import fs from 'fs'
const imsConfig = {
clientId: "daa0f550d4c641f68e08d1d74fcf594f",
clientSecret: "p8e-m0NLC7Jyh4PdxK6LXMI4Qm5OD-tS1lTF",
technicalAccountId: "55C94A89628B83F50A495F9C@techacct.adobe.com",
orgId: "3CC3266C626B9B030A495F8A@AdobeOrg",
metaScopes: ["ent_ccas_sdk"],
privateKey: fs.readFileSync("private.key").toString().trim(),
};
async function genearteIMSToken() {
let creds = await auth(imsConfig);
// 这就是新的jwttoken
return creds;
// 完整带 bear的token
return `${creds.token_type}${creds.access_token}`
}
// creads结果
export interface JWTAuthResponse {
token_type: "bearer";
access_token: string;
expires_in: number;
}
python
因为jwt库的版本升级,adobe的官方示例基本失效,下面是修复后的代码2022年6月位置能用的修复版
- 安装依赖
pip install jwt requests
import time, requests
from os import path
from pydantic import HttpUrl
from jwt import JWT, jwk_from_pem
class Config:
api_key: str = "xx"
org_id: str = "xxx@AdobeOrg"
tech_id: str = "xxx"
secret: str = "xxx"
class AdobeAPI:
JWT: HttpUrl = "https://ims-na1.adobelogin.com/ims/exchange/jwt/"
METHOD: str = "get"
hello_word: HttpUrl = "https://image.adobe.io/pie/psdService/hello"
smart_object: HttpUrl = "https://image.adobe.io/pie/psdService/smartObject"
private_key_path: str = path.abspath("key/psd/private.key")
def retrieving_token(url: HttpUrl, config: Config) -> str:
"""
注册续期jwt的token
- param url :{HttpUrl} {description}
- param config :{Config} {description}
"""
with open(AdobeAPI.private_key_path, "rb") as f:
private_key_unencrypted = jwk_from_pem(f.read())
header_jwt = {
"cache-control": "no-cache",
"content-type": "application/x-www-form-urlencoded",
}
jwtPayload = {
"exp": round(24 * 60 * 60 + int(time.time())), ### Expiration set to 24 hours
"iss": config.org_id, ### org_id
"sub": config.tech_id, ### technical_account_id
# "https://ims-na1.adobelogin.com/s/ent_user_sdk": True,
"https://ims-na1.adobelogin.com/s/ent_ccas_sdk": True,
"aud": f"https://ims-na1.adobelogin.com/c/{config.api_key}", ##api_key is your API KEY
} ## I set the different information required in request
##make sure to use the RS256 algo
encoded_jwt = JWT().encode(jwtPayload, private_key_unencrypted, alg="RS256")
payload = {
"client_id": config.api_key,
"client_secret": config.secret,
"jwt_token": encoded_jwt.encode("utf-8"),
}
##using the requests library to ask for the token
response = requests.post(url, headers=header_jwt, data=payload)
json_response = response.json()
token = json_response["access_token"] ## retrieve the token
expire = json_response["expires_in"] ##retrieving when the token expire
## getting the scope right
global date_limit
date_limit = (
time.time() + expire / 1000 - 500
) ## end of time for the token, taking 500 s interval
print(
"token valid till : " + time.ctime(time.time() + expire / 1000)
) ##show me in the console how long the token is working
return token
token = retrieving_token(AdobeAPI.JWT, Config)