LWP::A...::Line(3pm)
π NAME π
LWP::Authen::OAuth2::ServiceProvider::Line β bestie, this is the service provider plug-in that gets you into the Line OAuth2 API v2. It lives in the User Contributed Perl Documentation section of your friendly neighbourhood perl v5.36.0 install, and it's here to make Line auth actually make sense. π¦
β¨ VERSION β¨
version 0.20 β tiny number, huge vibes. π
πΈ SYNOPSIS πΈ
okay so here's the whole ~journey~, from "hey let's log in" all the way to revoking tokens. Read it like a group chat, top to bottom:
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 });
heads up: the two credential lines in ->new(...) have a comment right after the value and no trailing comma, so if you add more args after them you'll want to fix that up. Copy the example as-is and you're golden. π
π REGISTERING π
so like, individual users need to have an account made with the Line application at <https://line.me/download>. That's step one, no skipping. π«Ά
and to actually log in with OAuth2? Users must register their email address. Like, it's required, fr fr. Device-specific instructions live on the Line support site at <https://help.line.me/> if you get lost.
API clients (that's you, dev bestie π) can follow the Line Login docs at <https://developers.line.me/line-login/overview> to set up the OAuth2 credentials.
π± Line API Documentation π±
Go read the Line Social REST API Reference at <https://devdocs.line.me/en/#how-to-use-the-apis> β it's the source of truth, and it's giving β¨documentationβ¨.
As of writing, there are two simple API calls: profile and refresh. Easy. Iconic. No notes.
There are also verify and revoke endpoints, which β plot twist β require a bit more work. π Let's get into it:
π verify π
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 so you can send it in the request body. The LWP::Authen::OAuth2::ServiceProvider::Line::AccessToken token class used by this service provider provides the access_token accessor for exactly this purpose. π
The server seems to ignore the Authorization header for this request, so including it is probably not a problem. But 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 "SYNOPSIS" for usage examples. β¬οΈ
ποΈ revoke ποΈ
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 so you can send it in the request body. The LWP::Authen::OAuth2::ServiceProvider::Line::AccessToken token class used by this service provider provides the refresh_token accessor for exactly this purpose. See "SYNOPSYS" for usage examples.
(yes, it says SYNOPSYS in the original β I'm keeping it, character for character, because that's the whole bit. π)
β° Refresh timing β°
Line access tokens can be refreshed at any time up until 10 days after the access token expires. That's the window, bestie β respect it.
The LWP::Authen::OAuth2::ServiceProvider::Line::AccessToken token class used by this service provider extends the should_refresh method for this purpose, which causes $oauth2->should_refresh() to return false if this 10-day period has lapsed. So it just... tells you no. Politely. π
π AUTHOR π
Adam Millerchip, <adam at millerchip.net>
π― AUTHORS π―
- Ben Tilly,
<btilly at gmail.com> - Thomas Klausner
<domm@plix.at>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2013 - 2022 by Ben Tilly, Rent.com, Thomas Klausner.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. slay. π
okay that's the whole page, you made it to the end, I'm so proud of you π₯Ή this was documented for perl v5.36.0 and dated 2023-02-04, and it's filed away as User Contributed Perl Documentation β now go get those tokens, main character. π
β¨π¦
π¦ where this page comes from
- debian bookworm: liblwp-authen-oauth2-perl 0.20-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: liblwp-authen-oauth2-perl 0.20-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: liblwp-authen-oauth2-perl 0.20-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: liblwp-authen-oauth2-perl 0.20-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liblwp-authen-oauth2-perl 0.20-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms