Why not adopt me?
NAME
Net::OAuth2::AccessToken - OAuth2 bearer token
SYNOPSIS
my $auth = Net::OAuth2::Profile::WebServer->new(...);
my $token = $auth->get_access_token($code, ...);
# $token is a Net::OAuth2::AccessToken
if($token->error)
{ print $token->error_description;
}
my $response = $token->get($request);
my $response = $token->get($header, $content);
print $token->to_string; # JSON
# probably better to set new(auto_refresh), but you may do:
$token->refresh if $token->expired;
DESCRIPTION
This object represents a received bearer token, and offers ways to use it.
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.
METHODS
Constructors
- Net::OAuth2::AccessToken->new(OPTIONS)
-
-Option --Default access_token undef auto_refresh <false> error undef error_description <value of error> error_uri undef expires_at undef expires_in undef profile <required> refresh_token false scope undef token_type undef
- access_token => STRING
- auto_refresh => BOOLEAN
-
Refresh the token before each use.
- error => STRING
-
Set when an error has occured, the token is not valid. This is not numerical.
- error_description => STRING
-
A humanly readible explanation on the error. This defaults to the string set with the
error
option, which is not nice to read. - error_uri => URI
-
Where to find more details about the error.
- expires_at => TIMESTAMP
-
Expire this token after TIMESTAMP (as produced by the time() function)
- expires_in => SECONDS
-
Expire the token SECONDS after the initiation of this object.
- profile => Net::OAuth2::Profile object
- refresh_token => BOOLEAN
-
Auto-refresh the token at each use.
- scope => URL
- token_type => TYPE
Accessors
- $obj->access_token()
-
Returns the (base64 encoded version of the) access token. The token will get updated first, if it has expired and refresh_token is enabled, or when new(auto_refresh) is set.
It does not matter that the token is base64 encoded or not: it will always need to be base64 encoded during transport.
- $obj->auto_refresh()
- $obj->error()
- $obj->error_description()
- $obj->error_uri()
- $obj->expired([AFTER])
-
Returns true when the token has an expiration set and that time has passed. We use this token AFTER this check: to avoid the token to timeout inbetween, we take (by default 15 seconds) margin.
- $obj->expires_at([TIMESTAMP])
-
Returns the expiration timestamp of this token (true) or
undef
(false) when it is not set. - $obj->expires_in()
-
Returns the number of seconds left, before the token is expired. That may be negative.
- $obj->profile()
- $obj->refresh_token()
- $obj->scope()
- $obj->token_type()
- $obj->update_token(TOKEN, TOKENTYPE, EXPIRES_AT)
-
Change the token.
Action
- $obj->delete(URI, [HEADER, [CONTENT]])
- $obj->get(URI, [HEADER, [CONTENT]])
- $obj->post(URI, [HEADER, [CONTENT]])
- $obj->put(URI, [HEADER, [CONTENT]])
- $obj->refresh()
-
Refresh the token, even if it has not expired yet. Returned is the new access_token value.
- $obj->request(REQUEST)
- $obj->to_string()
-
Serialize this object into JSON.
SEE ALSO
This module is part of Net-OAuth2 distribution version 0.50, built on January 07, 2013. Website: http://perl.overmeer.net.
COPYRIGHTS
Copyrights 2012-2013 on the perl code and the related documentation by [Mark Overmeer]. For other contributors see Changes.
Copyrights 2011 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://www.perl.com/perl/misc/Artistic.html