| Net::OAuth2::AccessToken(3pm) | User Contributed Perl Documentation | Net::OAuth2::AccessToken(3pm) |
Net::OAuth2::AccessToken - OAuth2 bearer token
my $auth = Net::OAuth2::Profile::WebServer->new(...);
my $session = $auth->get_access_token($code, ...);
# $session is a Net::OAuth2::AccessToken object
if($session->error)
{ print $session->error_description;
}
my $response = $session->get($request);
my $response = $session->get($header, $content);
print $session->to_string; # JSON
# probably better to set new(auto_refresh), but you may do:
$session->refresh if $session->expired;
This object represents a received (bearer) token, and offers ways to use it and maintain it. A better name for this module would include client or session.
A "bearer token" is an abstract proof of your existence: different services or potentially different physical servers are able to exchange information about your session based on this, for instance whether someone logged-in while showing the token.
-Option --Default
access_token undef
auto_refresh <false>
changed <false>
error undef
error_description <value of error>
error_uri undef
expires_at undef
expires_in undef
profile <required>
refresh_always BOOLEAN
refresh_token false
scope undef
token_type undef
You may pass any of the parameters for new() as %options, to overrule the values inside the $session.
-Option --Default
profile <required>
example:
my $auth = Net::OAuth2::Profile::WebServer->new(...);
my $token = $auth->get_access_token(...);
my $session = $token->session_freeze;
# now save $session in database or file
...
# restore session
my $auth = Net::OAuth2::Profile::WebServer->new(...);
my $token = Net::OAuth2::AccessToken->session_thaw($session
, profile => $auth);
It does not matter that the token is base64 encoded or not: it will always need to be base64 encoded during transport.
errors
When the token is received (hence this object created) it be the result of an error. It is the way the original code was designed...
Expiration
The "changed" flag will be cleared by this method.
Be sure that your storage is character-set aware. For instance, you probably want to set 'mysql_enable_utf8' when you store this in a MySQL database. Perl's JSON module will output utf8 by default.
HTTP
The token can be encoded in transport protocol in different ways. Using these method will add the token to the HTTP messages sent.
Copyrights 2013-2019 on the perl code and the related
documentation
by [Mark Overmeer <markov@cpan.org>] for SURFnet bv, The Netherlands.
For other contributors see "Changes".
Copyrights 2011-2012 by Keith Grennan.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/
| 2021-10-15 | perl v5.32.1 |