登录
首页 >  Golang >  Go问答

EPIC FHIR SMART 后端服务:{ "error": "invalid_client", "error_description": null }

来源:stackoverflow

时间:2024-04-23 16:39:35 221浏览 收藏

“纵有疾风来,人生不言弃”,这句话送给正在学习Golang的朋友们,也希望在阅读本文《EPIC FHIR SMART 后端服务:{ "error": "invalid_client", "error_description": null }》后,能够真的帮助到大家。我也会在后续的文章中,陆续更新Golang相关的技术文章,有好的建议欢迎大家在评论留言,非常感谢!

问题内容

我正在尝试实施 epic fhir smart 后端服务(后端 oauth 2.0) on go 编程语言。

我已经创建了我的开发帐户,在其中上传了公钥,并选择 backend 系统 作为应用程序受众。

我很确定我的 jwt 令牌是正确的。我在 jwt.io 上检查过,签名是正确的。但是,我总是收到此错误:

{“错误”:“invalid_client”,“error_description”:null }

我也尝试过其他可能的解决方案,例如:

  • 确保飞机索赔的有效期低于 5 分钟
  • 将有效负载放入正确内容类型的正文中,即 application/x-www-form-urlencoded
  • 确保使用沙箱 client_id
  • 使用正确的 jwt 登录方法 (rs384)

我应该怎么做才能解决这个问题?

顺便说一句,我还在 google 群组上看到了一些讨论,说在创建开发帐户后等待一两天是值得的。

下面是我的代码。感谢您的帮助!

var (
    oauth2TokenUrl  = "https://fhir.epic.com/interconnect-fhir-oauth/oauth2/token"
    sandboxClientID = "..."
    privateKey      = "..."
)

// load private key
signKey, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(privateKey))
So(err, ShouldBeNil)

// construct jwt claims
now := time.Now()
claims := jwt.MapClaims{
    "iss": sandboxClientID,
    "sub": sandboxClientID,
    "aud": oauth2TokenUrl,
    "jti": uuid.New().String(),             // fill with reference id
    "exp": now.Add(1 * time.Minute).Unix(), // cannot be more than 5 minutes!
}
log.Info("  => claims:", utility.ToJsonString(claims))

// generate signed token using private key with RS384 algorithm
alg := jwt.SigningMethodRS384
signedToken, err := jwt.NewWithClaims(alg, claims).SignedString(signKey)
So(err, ShouldBeNil)
log.Info("  => signed token", signedToken)

// prepare api call payload
payload := map[string]string{
    "grant_type":            "client_credentials",
    "client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
    "client_assertion":      signedToken,
}

// dispatch the api call
req := resty.New().
    R().
    EnableTrace().
    SetFormData(payload)
res, err := req.Post(oauth2TokenUrl)
So(err, ShouldBeNil)
log.Info("  => response status:", res.StatusCode())
log.Info("  => response header:", res.Header())
log.Info("  => response body:", string(res.Body()))

// parse response
resBody := make(map[string]interface{})
err = json.Unmarshal(res.Body(), &resBody)
So(err, ShouldBeNil)

正确答案


太棒了,我现在可以使用了。

解决方案就是等待!这很令人困惑,因为我在文档中找不到任何关于此的解释,而且错误消息也不太友好。

总之,在创建开发应用程序并将公钥上传到那里后,我们必须等待几个小时/几天,然后凭证最终才能使用。

等待部分适用于开放史诗应用程序果园开发帐户。

更新#1

以防万一有人在几个小时后仍然遇到相同的错误,可能值得检查 EPIC 的以下指南。

https://fhir.epic.com/Resources/jwt_auth_troubleshoot_eof

Epic似乎有某种每天运行一次的同步机制。因此,创建帐户后等待是唯一的解决方案。另请注意,在应用设置中 Endpoint URI 更改后,您还需要等待一段时间。

错误 { "error": "invalid_client", "error_description": null }当 redirect_uri 参数设置为类似 localhost:3000 时, 也会显示。

以上就是《EPIC FHIR SMART 后端服务:{ "error": "invalid_client", "error_description": null }》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>