该问题特定于版本 v2。 v1 工作正常,但无法与第二个版本连接。我们无法获取第一个授权码。一切看上去都符合文献记载,尽管它极其歪曲。我将用 Python 发布代码。谁能告诉我。错误 error_description":"ESIA-007053: OAuthErrorEnum.clientSecretWrong
def sign_params_for_v2_by_csptest(client_secret_raw):
"""
:param client_secret_raw: Сформированный для подписания файл
:return:
"""
thumbprint = ""
tmp_dir = tempfile.gettempdir()
source_file = tempfile.NamedTemporaryFile(mode='w', delete=False, dir=tmp_dir)
source_file.write(client_secret_raw)
source_file.close()
source_path = source_file.name
destination_path = source_path + ".sig"
cmd = (f'/opt/cprocsp/bin/amd64/csptest -keys -sign GOST12_256 -cont "имя контейнера" -keytype exchange -in {source_path} -out {destination_path}')
os.system(cmd)
signed_message = open(destination_path, 'rb').read()
os.unlink(source_path)
os.unlink(destination_path)
"""
Возвращает base64url подписанное значение
"""
return base64.urlsafe_b64encode(signed_message).decode('utf-8')
TIMESTAMP = get_timestamp()
CLIENT_ID = "имя"
SCOPE = "openid"
SCOPE_ORG = "org_inn"
REDIRECT_URI = "урл"
SERVICE_URL = "https://esia-portal1.test.gosuslugi.ru/aas/oauth2/v2/ac"
STATE = str(uuid.uuid4())
#Формируем client для подписания
client_secret_raw = (
CLIENT_ID +
SCOPE.replace(" ", "") +
SCOPE_ORG +
TIMESTAMP +
STATE +
REDIRECT_URI
)
client_secret = sign_params_for_v2_by_csptest(client_secret_raw)
client_hash = "hash через calc_cert_hash_unix"
params_url = {
"client_id": CLIENT_ID,
"scope": SCOPE,
"scope_org": SCOPE_ORG,
"timestamp": TIMESTAMP,
"state": STATE,
"redirect_uri": REDIRECT_URI,
"client_secret": client_secret,
"response_type": "code",
"access_type": "offline",
"client_certificate_hash": client_hash,
}
params = urlencode(sorted(params_url.items()))
url = f"{SERVICE_URL}?{params}"
print("URL:", url)
简而言之,它可能对某些人有用。我正在以工作代码的形式提出这个问题的解决方案。简而言之,存在几个问题。谁会做只需获取代码,写下你的'client_certificate_hash':'Hash','client_id':client_idn,redirect_uri =“重定向”和容器名称cont = f“容器名称”。一切都应该顺利进行以获取代码。主要还是看f'/opt/cprocsp/bin/amd64/csptest本身所在的路径