简体   繁体   English

我想将 XERO 集成到 WebAPI C# 有人可以为我提供 oauth2 的示例代码吗

[英]I want to integrate XERO to WebAPI C# Can someone provide me sample code for oauth2

I have tried the below我已经尝试过以下

        XeroConfiguration xeroConfig = new XeroConfiguration();
        xeroConfig.ClientId = "****";
        xeroConfig.ClientSecret = "****";
        xeroConfig.CallbackUri = new Uri("http://localhost"); //default for standard webapi template
        xeroConfig.Scope = "openid profile email files accounting.transactions accounting.contacts offline_access";
        var client2 = new XeroClient(xeroConfig, httpClientFactory);
        var test = client2.BuildLoginUri();

        return Redirect(client2.BuildLoginUri());

After redirection it is giving below error Error code: 500 Error: unauthorized_client: Invalid redirect_uri重定向后,它给出以下错误错误代码:500 错误:未授权客户端:无效的 redirect_uri

It is because you have registered your app in the Authorization Server using a different redirect URI and in the above you are using a different redirect URI which will be validated by the Authorization Server and on mismatch, it is throwing you the Error.这是因为您使用不同的重定向 URI 在授权服务器中注册了您的应用程序,并且在上面您使用了不同的重定向 URI,该 URI 将由授权服务器进行验证,并且在不匹配时,它会向您抛出错误。

You have to register your app with the Redirect URI that you will be using您必须使用您将使用的重定向 URI 注册您的应用程序

Ex: If your app is running in http://localhost:6500 and your redirect URI to receive the token and process is http://localhost:6500/login .例如:如果您的应用程序在http://localhost:6500中运行,并且您接收令牌和进程的重定向 URI 是http://localhost:6500/login You have to provide this value to the Authorization Server.您必须将此值提供给授权服务器。

ex: The setting would look like例如:设置看起来像

xeroConfig.CallbackUri = new Uri("http://localhost:6500/login")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM