Created
April 5, 2012 10:46
-
-
Save nikopol/2309905 to your computer and use it in GitHub Desktop.
Net-OAuth2 with refresh sample usecase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#load token if previously saved | |
if( my $data = read_file( $tokenfile ) ) { | |
$self->{token} = $data; | |
} | |
#instanciate api with token_or_undef | |
$self->{api} = Net::OAuth2::Client->new( | |
$self->{client_id}, | |
$self->{client_secret}, | |
site => $self->{site}, | |
authorize_path => $self->{authorize_path}, | |
access_token_path => $self->{access_token_path}, | |
access_token_method => $self->{access_token_method}, | |
access_token_param => $self->{access_token_param}, | |
scope => $self->{scope}, | |
)->web_server( | |
redirect_uri => $self->{callback} | |
)->get_access_token( | |
%{$self->{token}} | |
); | |
#... | |
# uses of $self->{api}->access_token() automically refreh it if needed | |
#and finally save the token | |
write_file $tokenfile => { $self->{api}->save }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment