LWP::Authen::OAuth2::ServiceProvider::Line - Access Line OAuth2 API v2
my $oauth2 = LWP::Authen::OAuth2->new( service_provider => 'Line', redirect_uri => 'http://example.com/', client_id => 'line_client_id' # Retrieved from https://developers.line.me/ client_secret => 'line_client_secret' # Retrieved from https://developers.line.me/ ); my $url = $oauth2->authorization_url(state => $state); # ... Send user to authorization URL and get authorization $code ... $oauth2->request_tokens(code => $code); # Simple requests # User Info my $profile = $oauth2->make_api_call('profile'); my $userId = $profile->{userId}; my $displayName = $profile->{displayName}; my $pictureUrl = $profile->{pictureUrl}; my $statusMessage = $profile->{statusMessage}; # Refresh $oauth2->refresh_access_token(); # More complex requests... # Verify # Manually send the request using the internal user agent - see explanation in "Line API Documentation" below. my $access_token_str = $oauth2->access_token->access_token; my $res = $oauth2->user_agent->post($oauth2->api_url_base.'oauth/verify' => { access_token => $access_token_str }); my $content = eval { decode_json($res->content) }; my $scope = $content->{scope}; my $client_id = $content->{client_id}; my $expires_in = $content->{expires_in}; # Revoke # Look up the internal refresh token - see explanation in "Line API Documentation" below. my $refresh_token_str = $oauth2->access_token->refresh_token; $oauth2->post($oauth2->api_url_base.'oauth/revoke' => { refresh_token => $refresh_token_str });
Individual users must have an account created with the Line application. In order to log in with OAuth2, users must register their email address. Device-specific instructions can be found on the Line support site.
API clients can follow the Line Login documentation to set up the OAuth2 credentials.
See the Line Social REST API Reference.
As of writing, there are two simple API calls: profile and refresh.
profile
refresh
There are also verify and revoke endpoints, which require a bit more work.
verify
revoke
verify is designed for verifying pre-existing access tokens. Instead of using the Authorization header, this endpoint expects the access token to be form-urlencoded in the request body. Because of this, it's necessary to get access to the internal access token string to send in the request body. The LWP::Authen::OAuth2::ServiceProvider::Line::AccessToken token class used by this service provider provides the access_token accessor for this purpose.
Authorization
access_token
The server seems to ignore the Authorization header for this request, so including it is probably not a problem. If you want to avoid sending the access token in the header, it's necessary to manually construct the request and decode the response.
See "SYNOPSYS" for usage examples.
revoke requires the refresh token to be form-urlencoded in the request body. Because of this, it's necessary to get access to the internal refresh token string to send in the request body. The LWP::Authen::OAuth2::ServiceProvider::Line::AccessToken token class used by this service provider provides the refresh_token accessor for this purpose. See "SYNOPSYS" for usage examples.
refresh_token
Line access tokens can be refreshed at any time up until 10 days after the access token expires. The LWP::Authen::OAuth2::ServiceProvider::Line::AccessToken token class used by this service provider extends the should_refresh method for this purpose, causing $oauth2->should_refresh() to return false if this 10-day period has lapsed.
should_refresh
$oauth2->should_refresh()
Adam Millerchip, <adam at millerchip.net>
<adam at millerchip.net>
To install LWP::Authen::OAuth2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm LWP::Authen::OAuth2
CPAN shell
perl -MCPAN -e shell install LWP::Authen::OAuth2
For more information on module installation, please visit the detailed CPAN module installation guide.