Monks,
I have spent the last 2 days scouring the internet for information on how to authenticate a perl app using oauth2. There are a half-dozen modules that claim to assist with this process, and not a single one has documentation or examples or any hint on how to construct the request successfully.
I decided to work with LWP::Authen::OAuth2 and came up with the following code (This is for attempting to authenticate with Yahoo).
The number one issue I have is the redirect_uri. It seems like the oauth2 spec always assumes that any developer has access to their own website to host a redirect page on? This must be super-obvious, because every tutorial site just hand-waves over this parameter with "put your redirect uri here" without even attempting to suggest what one might look like, especially if you're running a standalone application. Some sites mentioned that you can redirect to localhost... again, without any sort of suggestion as to how you might do that.
So... question 1. How to I form a redirect URI for a locally executed application in a windows environment?
I'm sure I have more questions and errors in my code, but I won't be able to find those until I can fill in some reasonable value for the redirect_uri.
use LWP::Authen::Oauth2; use Storable; #to save and restore token for future use use Term::Prompt; use strict; use warnings; my $oauth2 = LWP::Authen::OAuth2->new( client_id => '*****', client_secret => '*****', redirect_uri => 'I don't even know', scope => 'fspt-w', response_type => 'id_token' ); my $url = $oauth2->authorization_url('https://api.login.yahoo.com/oaut +h2/request_auth'); my $code = prompt('x', 'Paste the code obtained at the above URL here: + ', '', ''); # Exchange the code for an access token: my $token = $oauth2->get_access_token($code) or die; # If we get to here, it worked! Report success: print "\nToken obtained successfully!\n"; print "Here are the token contents (just FYI):\n\n"; print $token->to_string, "\n";
In reply to Oauth2 help needed by superwombat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |