简体   繁体   中英

How to encode the redirect_uri for facebook login

I'm trying to build a login link for facebook and I'm I'm getting errors only in some cases. I'm trying to specify aa querystring parameter in redirect_uri token so that I can redirect them back to a specific area of my site after logging in. Here's what works and what doesn't work.

&redirect_uri=http://mydomain.com/login?returnUrl=returnUrl - works &redirect_uri=http://mydomain.com/login?returnurl=/return/url -doesn't work &redirect_uri=http%3a%2f%2fmyagentcheckin.com%2flogin%3freturnUrl%3d%2freturn%2furl -doesn't work

It seems that the / in the querystring are causing it to fail. Facebook returns an error when I try it. Anyone know of a way around this?

Instead of including the returnUrl parameter as part of your redirect_uri value, use the state parameter to store this data.

For instance,

https://graph.facebook.com/oauth/authorize?type=web_server&client_id= {appid}&redirect_uri=http://www.yoursite.com/oauth/handshake&state=/requested/page

I have experienced something similar, especially with multiple redirects as above.

My solution is to put the returnUrl into the user's session (or perhaps a cookie), so I don't have to wrestle with double-encoding. For the redirect_url, just omit the querystring.

Try using this API that put together. It will remove the hassle of this for you.

No url encoding necessary.

Sample Authentication

Imports Branches.FBAPI
...
Dim SI As New SessionInfo("[application_id]","applicaiton_secret")
SI.AuthenticateUser("http://[my url]", New SessionInfo.PermissionsEnum(){SessionInfo.PermissionsEnum.email, SessionInfo.PermissionsEnum.read_stream}))

Read the response from the URL you provided above from that page.

Dim FSR = FS.ReadFacebooAuthResponse

When I tried what you do, I got a redirect callback something like this. http://mydomain.com/login?returnurl=%2Freturn%2Furl&code= ...

And I decode the "returnurl" value. Then it worked fine for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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