与 MSAL(Azure AD) 和 GoLang 集成:未定义
我正在将我的 Go Gin 应用程序与公司的 Azure AD 集成,参考:https ://github.com/AzureAD/microsoft-authentication-library-for-go,但是,它在开始的步骤中失败了。
我在这一行中得到了 "undefined: publicClientApp"
:
publicClientapp, err := public.New("client_id", public.WithAuthority("https://login.microsoftonline.com/Enter_The_Tenant_Name_Here"))
有谁知道为什么会发生这种情况? Go和AAD有成功的例子吗?
官方的例子不太清楚,而且有很多错误,让我很困惑。 谢谢!
I'm integrating my Go Gin app with Azure AD for the company, ref: https://github.com/AzureAD/microsoft-authentication-library-for-go , however, it failed in the beginning step.
I got "undefined: publicClientApp"
in this line:
publicClientapp, err := public.New("client_id", public.WithAuthority("https://login.microsoftonline.com/Enter_The_Tenant_Name_Here"))
Does anyone know why this happens?
Are there any successful examples for Go and AAD?
The official example is not clear and there are so many errors which quite confused me.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎工作得很好。
https://go.dev/play/p/WERsd46004p
您显示错误消息
"undefined: publicClientApp"
但您将客户端声明为publicClientapp
。如果您随后尝试使用publicClientApp
,您将看到该错误,因为它尚未定义。 (注意大写的 A)。This seems to work just fine.
https://go.dev/play/p/WERsd46004p
You show the error message
"undefined: publicClientApp"
but you are declaring the client aspublicClientapp
. If you attempt to usepublicClientApp
afterwards, you will see that error, as it has not been defined. (Note the uppercase A).希望您在使用之前已经声明了变量。
请检查客户端 ID 是否获得了正确的 appId 值,或者尝试从环境变量或 json 文件(如果存在)中获取。
如果声明的变量在分配了一些值之后没有在任何地方使用,就会发生这种类型的错误。
请在检查所有参数是否正确后检查是否使用了 publicclientapp。类似于参考文献中的步骤 2。
当我们检查 nil 值的错误时,类似于尝试检查客户端应用程序是否具有某些值。并查看是否缺少任何额外参数或未缓存。
参考文献:
Hope you have declared variables before use .
Please check if the client id is given correct value of appId or try to take from environment variables or json file if present.
This type of error occurs if the declared variable is not used any where even after assigning some value .
Please check if publicclientapp is used after checking if all arguments are correct.something like in step 2 in your reference.
As we check error for nil value , similar to that try to check client app has some value .And see if any extra argument is missing or not cacheing.
References: