Skip to content

Instantly share code, notes, and snippets.

@nikopol
Created April 5, 2012 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikopol/2309905 to your computer and use it in GitHub Desktop.
Save nikopol/2309905 to your computer and use it in GitHub Desktop.
Net-OAuth2 with refresh sample usecase
#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