Skip to content

Instantly share code, notes, and snippets.

@t-kashima
Created May 3, 2012 09:08
Show Gist options
  • Save t-kashima/2584528 to your computer and use it in GitHub Desktop.
Save t-kashima/2584528 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Mojolicious::Lite;
use OAuth::Lite::Consumer;
use Config::Pit;
use Data::Dumper;
my $config = pit_get('evernote.com');
my $consumer = OAuth::Lite::Consumer->new(
consumer_key => $config->{consumer_key},
consumer_secret => $config->{consumer_secret},
site => 'https://sandbox.evernote.com',
request_token_path => '/oauth',
access_token_path => '/oauth',
authorize_path => '/OAuth.action',
);
get '/' => sub {
my $self = shift;
$self->render(text => 'Hello');
};
get '/login' => sub {
my $self = shift;
my $request_token = $consumer->get_request_token(callback_url => $self->req->url->base . '/callback');
$self->session('request_token' => $request_token);
my $uri = $consumer->url_to_authorize(token => $request_token);
$self->redirect_to($uri);
};
get '/callback' => sub {
my $self = shift;
if ($self->param('oauth_token') && $self->param('oauth_verifier')) {
# Can't get, I need a shardId.
my $access_token = $consumer->get_access_token(
verifier => $self->param('oauth_verifier'),
);
$self->render(text => 'Hello' . Dumper $access_token);
} else {
$self->render(text => '/auth');
}
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment