DotNetOpenAuth OAuth 2.0 authorization with Google

懵懂的女人 提交于 2019-12-06 04:43:19

You should use the "state" to store information on post authentication redirects

To stop DNOA setting a state automatically and allowing you to set your own one create a implementation of IClientAuthorizationTracker

Public Class TokenManager
 Implements IClientAuthorizationTracker

 Function GetAuthorizationState(callbackUrl As System.Uri, clientState As String) As IAuthorizationState Implements IClientAuthorizationTracker.GetAuthorizationState
  Dim oAS As AuthorizationState = Nothing
            If True Then
                oAS = New AuthorizationState()
                oAS.Callback = callbackUrl
            End If
        Return oAS
    End Function
End Class

and then

oClient = New WebServerClient(MyAuthDesc)
...
oClient.AuthorizationTracker = New TokenManager

lastly (When ProcessUserAuthorization() returns Null/Nothing)

Dim owr As DotNetOpenAuth.Messaging.OutgoingWebResponse
owr = oClient.PrepareRequestUserAuthorization(scopes:=sScope, returnTo:=Request.Url) 
oOAuthParams.Redirect = owr.Headers.Item("Location") & "&state=" & sReturnHere

When ProcessUserAuthorization succeeds and you verify your access token then you can read the state in the URL and do something with it (I do not use it to return I actually use it to discourage fraud)

I needed to do the above anyway to get DNOA working as I did not want to use the session object

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!