Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by fred_gds · Mar 16, 2016 at 04:36 PM · serverfacebookurlserversidetoken

Capture redirection Url

Hello,

I am trying to capture the access token of Facebook which is apparently provided in a redirection URL. So I call the following function in my application:

  Application.OpenURL(String.Format("https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&state={2}", _facebookAppId, _redirectEndpoint, token));

_redirectEndpoint is my Server (www.someWebServer.com).

"When using a desktop app and logging in, Facebook redirects people to the redirect_uri mentioned above and places an access token along with some other metadata (such as token expiry time) in the URI fragment:"

is what it says on the Facebook guide

So I would like to create a script that captures the entire URI, so that I can retrieve in with my application. It should not be that hard but unfortunately I am not that familiar with server side scripting so it would be great tif somebody could help me out :)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Phedg1 · Nov 20, 2019 at 01:54 AM 0
Share

Sorry about the necro. Did you end up finding a solution to this?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Mar 16, 2016 at 05:14 PM

Application.OpenURL on most platforms opens that URL in a webbrowser so it has nothing to do with your application anymore. If called in a webbuild you effectively redirect the user to that new URL which in turn will replace the website where your webplayer / WebGL build run on.

You don't want to use Application.OpenURL. Such dynamic load operations are usually done with the WWW class. However in this case it can't be used since the WWW class automatically follows redirect responses (at least that's what the behaviour was in the past, haven't checked recently). That means you don't get the intermediate result which contains the information you need.

There are basically two ways:

  • At the redirect URL that you give facebook you should run some php script that simply echos back the URL parameters that it receives. When doing so you can use the WWW class to perform that task. The WWW class would automatically redirect to your given URL including the information passed by facebook. That means what the WWW class will return is what your PHP script returns. That way you can gather the information needed.

  • Use a socket implementation that doesn't do a transparent redirect. When developing for standalone, mobile or Webplayer this should be possible with the usual .Net classes from the System.Net namespace. However in a WebGL build you can't use those classes. There you would need to do the request in native JavaScript using an XMLHttpRequest or similar AJAX interface that the browser offers.

I just read that the XMLHttpRequest also follows redirect responses transparently. Unless facebook uses a different response code than 301 you probably can't use the second solution for WebGL. This is probably for security reasons. So i guess the first approach is the only one that will actually work in all cases. The point of the "redirectEndpoint" is to ensure the information gets passed to that point only and there the information should be handled.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Mar 16, 2016 at 05:26 PM 0
Share

Just read that facebook seems to pass the information in the URI fragment. That's a problem since the fragment usually isn't sent to the server. So the PHP script can't read that information since it only exists on the clientside. As you can read in the SO post i linked in my answer it seems that some browsers provide a "responseURL" field which contains the URL that was actually loaded. However this doesn't seem to apply to all browsers. One quite nasty solution could be to load the request URL into a hidden iFrame on your webpage where you could run a javascript which extracts the information from the iFrame URL.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

42 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Server Based High Score - issues with adding new score 1 Answer

Unity 5 Download AssetBundles from server via URL. 2 Answers

MMORPG NPC/AI Simulation Movement and Position 0 Answers

Headless mode checkbox is uncheckable 1 Answer

can a server based android application be built in Unity? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges