7

I never used oauth before, so i wanted my app to open a url on system's default browser, then the user logs in, authorize, etc etc and then i need to send back the authorization code to my application, is there a way to do it? i'm using Trakt's API.

3
  • Due to browser security constraints, you may not be able to communicate directly back to the application. Design a web service 'middle man' which brokers the authentication. Commented Jan 13, 2015 at 19:48
  • unless you can register an external handler for an application specific URL scheme so the code is directly delivered to the application Commented Jan 13, 2015 at 22:06
  • How can i do that? i'm new at programming, is there a easier way to do this? i tried to open with webbrowser control, but it uses the lowest document mode available at it, which makes the auth page and the rest of the site awful... Commented Jan 14, 2015 at 2:17

1 Answer 1

14

There are multiple options, here are some of them:

  • use a custom URL scheme for a callback URL, e.g. "myapp://callback/after/oauth";
  • deliver authorization code inside of the browser title and watch the browser window title from your application;
  • temporary start a webserver from within your application and use a callback URL "http://localhost:port/".

Google recommends #2 and #3 for desktop applications. #1 is normally used for mobile: https://developers.google.com/accounts/docs/OAuth2InstalledApp

Sign up to request clarification or add additional context in comments.

2 Comments

Would you have a link showing what Google says exactly? Thanks!
How would I do option 2 or 3 for a macOS app? I found this answer by Manos (stackoverflow.com/questions/38268175/…) but I cannot find an httpListener

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.