NAME

OAuth::Simple - Simple OAuth authorization on your site

SYNOPSIS

my $oauth = OAuth::Simple->new(
    app_id     => 'YOUR APP ID',
    secret     => 'YOUR APP SECRET',
    postback   => 'POSTBACK URL',
);
my $url = $oauth->authorize( {url => 'https://www.facebook.com/dialog/oauth', scope => 'email', response_type => 'code'} );
# Your web app redirect method.
$self->redirect($url);
# Get access_token.
# Facebook returns data not in JSON. Use the raw mode and parse.
my $access = $oauth->request_access_token( {url => 'https://graph.facebook.com/oauth/access_token', code => $args->{code}, raw => 1} );
# Get user profile data.
my $profile_data = $oauth->request_data( {url => 'https://graph.facebook.com/me', access_token => $access} );  

DESCRIPTION

Use this module for input VK OAuth authorization on your site

METHODS

new

my $oauth = OAuth::Simple->new(
    app_id     => 'YOUR APP ID',
    secret     => 'YOUR APP SECRET',
    postback   => 'POSTBACK URL',
);

The new constructor lets you create a new OAuth::Simple object.

authorize

my $url = $oauth->authorize( {url => $authorize_server_url, option => 'value'} );
# Your web app redirect method.
$self->redirect($url);

This method returns a URL, for which you want to redirect the user.

Options

See information about options on your OAuth server.

Response

Method returns URI object.

request_access_token

my $access = $oauth->request_access_token( {url => $server_url, code => $args->{code}} );

This method gets access token from OAuth server.

Options

* code         - returned in redirected get request from authorize API method;
* raw          - do not decode JSON, return raw data;
* http_method  - set http method: GET(default), POST, etc.

Response

Method returns HASH object.

request_data

my $profile_data = $oauth->request( {
    url          => $api_method_url,
    access_token => $access_token,
    raw          => 1,
    http_method  => 'POST',
    token_name   => 'ouath_token',
});

This method sends requests to OAuth server.

Options

* url (required)          - api method url;
* params (not required)   - other custom params on OAuth server;
* access_token (required) - access token;
* raw                     - do not decode JSON, return raw data (default 0);
* http_method             - set http method: GET(default), POST, etc;
* token_name              - access token parameter name (default 'access_token').

Response

Method returns HASH object with requested data.

prepare_http_request

Returns HTTP::Request object.

OBJECT OPTIONS

no_token

If this parameter is 1, OAuth::Simple will not add access token parameter in request body. This option can be needed on working with The OAuth 2.0 Authorization Framework: Bearer Token Usage services. This services accepts access tokens only in special HTTP header.

OAuth::Simple->new(no_token => 1);

headers

Set HTTP headers, which used in prepare_http_request method.

OAuth::Simple->new( headers => { Content_Type => 'form-data' } );

SUPPORT

Github: https://github.com/Foxcool/OAuth-Simple

Bugs & Issues: https://github.com/Foxcool/OAuth-Simple/issues

AUTHOR

Alexander Babenko (foxcool@cpan.org) for Setup.ru (http://setup.ru)

CONTRIBUTORS

sugar: Anton Ukolov (aukolov@aukolov.ru)

COPYRIGHT

Copyright (c) 2012 - 2013 Alexander Babenko.