Oauth 2.0 使用Xojo和Chilkat实现OAuth2与Xero的集成
老奇尔卡特论坛似乎已经搬到这里 多年来,我一直让Chilkat的OAuth1在与Xero(来自Xojo)集成时运行良好。现在Xero正在用OAuth2替换OAuth1。 Xero说,一旦您成功连接到三条腿的OAuth2,您就可以使用刷新令牌保持重新连接,而无需每次都通过三条腿的过程(即用户协议允许您的连接)。因此,一旦您完成了一次三条腿的刷新,就不需要再做一次:每个未使用的刷新令牌在60天内保持有效(但只能使用一次)。 因此,这个过程似乎是:Oauth 2.0 使用Xojo和Chilkat实现OAuth2与Xero的集成,oauth-2.0,xero-api,chilkat,xojo,Oauth 2.0,Xero Api,Chilkat,Xojo,老奇尔卡特论坛似乎已经搬到这里 多年来,我一直让Chilkat的OAuth1在与Xero(来自Xojo)集成时运行良好。现在Xero正在用OAuth2替换OAuth1。 Xero说,一旦您成功连接到三条腿的OAuth2,您就可以使用刷新令牌保持重新连接,而无需每次都通过三条腿的过程(即用户协议允许您的连接)。因此,一旦您完成了一次三条腿的刷新,就不需要再做一次:每个未使用的刷新令牌在60天内保持有效(但只能使用一次)。 因此,这个过程似乎是: 三腿连接、手动批准、检索访问权限和刷新令牌 使用刷新
谢谢你的评论。我现在已经得到了这个工作,所以我张贴了我的回答谁有相同的问题 使用Xero Developer中的应用程序链接oauth2后,oauth2中的第一步是“三条腿”步骤,您必须获得用户批准。我一直无法让服务器工作(不允许重定向)。但是,由于您通常只需要执行一次,因此只需使用。基本上你只是:
// Set up the Authorisation:
Dim oauth2 As New Chilkat.OAuth2
'Set up from saved data:
oauth2.ClientId = { Client id used in initial setup }
oauth2.AccessToken = { access_token retrieved in setup }
oauth2.RefreshToken = { refresh_token: first retrieved in setup, then from each refresh }
oauth2.TokenEndpoint = "https://identity.xero.com/connect/token"
yourTenantID = { the <OrganisationID> of the <Organisation> you will be connecting to }
Dim success As Boolean
Dim rest As Chilkat.Rest
rest.Authorization = "Bearer " + oauth2.AccessToken
success = rest.AddHeader( "xero-tenant-id", yourTenantID)
'Responses will be in json: if you want xml, add this:
success = rest.AddHeader( "accept", "application/xml" )
//设置授权:
Dim oauth2作为新的Chilkat.oauth2
'从保存的数据设置:
oauth2.ClientId={初始设置中使用的客户端id}
oauth2.AccessToken={access\在安装程序中检索到的令牌}
oauth2.RefreshToken={refresh_token:首先在安装程序中检索,然后从每次刷新中检索}
oauth2.TokenEndpoint=”https://identity.xero.com/connect/token"
yourTenantID={您将要连接到的}
将成功视为布尔值
像孩子一样昏昏欲睡。休息
rest.Authorization=“Bearer”+oauth2.AccessToken
success=rest.AddHeader(“xero租户id”,yourTenantID)
'响应将采用json格式:如果需要xml,请添加以下内容:
success=rest.AddHeader(“接受”、“应用程序/xml”)
rest对象现在可以用于与Xero接口。例如,要获取一些数据:
// Get some data:
'endpoint is the endpoint you want, e.g. "Accounts"
'identifier and condition are optional parameters, see Xero's API Previewer
Dim sbPath As New Chilkat.StringBuilder
success = sbPath.Append( "/api.xro/2.0/" + endpoint )
if success then
if identifier>"" then
success = sbPath.Append("/" + identifier)
elseif condition>"" then
success = rest.AddQueryParam( "where" ,condition )
end if
end if
if not success then return rest.LastErrorText
// Get the full or matching list:
Dim sbXml As New Chilkat.StringBuilder
success = rest.FullRequestNoBodySb( "GET", sbPath.GetAsString(), sbXml)
dim statuscode As Integer = rest.ResponseStatusCode
if statuscode = 401 then
'access code expired: use refresh token to revive it and get new refresh token
success = oauth2.RefreshAccessToken()
if success then
{ Save the new oauth2.RefreshToken }
{ Disconnect and reconnect rest }
success = rest.FullRequestNoBodySb( "GET", sbPath.GetAsString(), sbXml)
end if
end if
if success then
If (rest.ResponseStatusCode <> 200) Then // A 200 response is expected for actual success
return sbXml.GetAsString()
else // get the response, in this case XML
Dim bAutoTrim As Boolean = True
success = xml.LoadSb(sbXml,bAutoTrim)
end if
end if
if not success then return rest.LastErrorText
//获取一些数据:
'端点是您想要的端点,例如“帐户”
'标识符和条件是可选参数,请参阅Xero的API预览器
将sbPath作为新的Chilkat.StringBuilder进行调整
success=sbPath.Append(“/api.xro/2.0/”+端点)
如果成功的话
如果标识符>则
success=sbPath.Append(“/”+标识符)
如果条件>“”那么
成功=rest.AddQueryParam(“where”,条件)
如果结束
如果结束
如果未成功,则返回rest.LastErrorText
//获取完整或匹配的列表:
将sbXml作为新的Chilkat.StringBuilder
success=rest.FullRequestNoBodySb(“GET”,sbPath.GetAsString(),sbXml)
dim statuscode为整数=rest.ResponseStatusCode
如果statuscode=401,则
'访问代码已过期:使用刷新令牌将其恢复并获取新的刷新令牌
success=oauth2.RefreshAccessToken()
如果成功的话
{保存新的oauth2.RefreshToken}
{断开并重新连接rest}
success=rest.FullRequestNoBodySb(“GET”,sbPath.GetAsString(),sbXml)
如果结束
如果结束
如果成功的话
如果是(rest.ResponseStatusCode 200),则//实际成功的响应预计为200
返回sbXml.GetAsString()
else//获取响应,在本例中为XML
Dim Bautottrim作为布尔值=真
success=xml.LoadSb(sbXml,bAutoTrim)
如果结束
如果结束
如果未成功,则返回rest.LastErrorText
您所说的“手动批准”可能是指用户交互(如对话框)?如果第1步工作正常,这意味着您可以向服务器传递用户名/密码或类似的信息,并取回令牌。然后将访问令牌传递给其他调用,通常作为一个特殊的http头。一旦出现“未授权”错误,您将使用刷新调用传递上一个刷新令牌并获得一个新的令牌对。因此,您需要记住两个最新的令牌,否则您将不得不再次登录。这是否使您走上了正确的道路?此外,您是否尝试过上面列出的示例,例如?