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.
Asked
Active
Viewed 8,961 times
6
-
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. – lcryder Jan 13 '15 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 – Hans Z. Jan 13 '15 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... – Gabriel Duarte Jan 14 '15 at 02:17
1 Answers
12
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

Vilmantas Baranauskas
- 6,596
- 3
- 38
- 50
-
1
-
How would I do option 2 or 3 for a macOS app? I found this answer by Manos (https://stackoverflow.com/questions/38268175/is-it-possible-to-use-oauth-2-0-without-a-redirect-server/39253876#39253876) but I cannot find an httpListener – Potion Mar 27 '19 at 20:45