0

我的程序在运行到 Dim context As Object = Await listener.GetContextAsync() 时拒绝继续,
但继续运行我从另一个表单调用 oauth2() 的下一行。它跳过运行这些行来获取此函数中的 AccessToken。它将显示Xero 组织选择窗口,但显示回调 url 无法显示在我的网络浏览器上。

如果我使用 Postman 进行测试,它会在单击并卸载 Xero 组织选择窗口后给我一个“身份验证失败 - 无法完成身份验证”错误消息。

欢迎任何帮助。

公共异步函数 oauth2() 作为任务(布尔值)

    Dim redirectUri As String = String.Format(callbackurl)
    Dim listener = New HttpListener()
    listener.Prefixes.Add(redirectUri)

    Try
        listener.Start()
        stopListening = False
    Catch hlex As HttpListenerException
        Return False
    End Try

    Dim urlCallBackFormat As String = WebUtility.UrlEncode(String.Format(callbackurl))
    Dim url As String = "https://login.xero.com/identity/connect/authorize?response_type=code&state=OzEPHd1GSvkwx0fnJ8023A&client_id=" & xeroClientId & "&scope=offline_access%20openid%20profile%20email%20accounting.settings%20accounting.transactions&redirect_uri=" & urlCallBackFormat
    Process.Start(url)

    While listener.IsListening
        Dim context As Object = Public Async Function oauth2() As Task(Of Boolean)
    Dim redirectUri As String = String.Format(callbackurl)
    Dim listener = New HttpListener()
    listener.Prefixes.Add(redirectUri)

    Try
        listener.Start()
        stopListening = False
    Catch hlex As HttpListenerException
        Return False
    End Try

    Dim urlCallBackFormat As String = WebUtility.UrlEncode(String.Format(callbackurl))
    Dim url As String = "https://login.xero.com/identity/connect/authorize?response_type=code&state=OzEPHd1GSvkwx0fnJ8023A&client_id=" & xeroClientId & "&scope=offline_access%20openid%20profile%20email%20accounting.settings%20accounting.transactions&redirect_uri=" & urlCallBackFormat
    Process.Start(url)


    While listener.IsListening
        Dim context As Object = Await listener.GetContextAsync()
        Try
            Await ProcessRequestAsync(context)
            stopListening = True
        Catch ex As Exception
            Console.WriteLine("# EXCEPTION #   " + ex.StackTrace)
        End Try
        If stopListening = True Then listener.Stop()
    End While



        Try
            Await ProcessRequestAsync(context)
            stopListening = True
        Catch ex As Exception
            Console.WriteLine("# EXCEPTION #   " + ex.StackTrace)
        End Try
        If stopListening = True Then listener.Stop()
    End While
4

0 回答 0