---
name: "OAuth::Lite2::Server::Endpoint::Token"
section: "3pm"
platform: "linux"
package: "liboauth-lite2-perl"
version: "0.11-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/OAuth::Lite2::Server::Endpoint::Token"
---

# OAuth::Lite2::Server::Endpoint::Token(3pm)

token endpoint PSGI application

## NAME

OAuth::Lite2::Server::Endpoint::Token - token endpoint PSGI application

## SYNOPSIS

token\_endpoint.psgi

```
    use strict;
    use warnings;
    use Plack::Builder;
    use OAuth::Lite2::Server::Endpoint::Token;
    use MyDataHandlerClass;
    builder {
        my $app = OAuth::Lite2::Server::Endpoint::Token->new(
            data_handler => 'MyDataHandlerClass',
        );
        $app->support_grant_types(qw(authorization_code refresh_token));
        $app;
    };
```

## DESCRIPTION

The instance of this class behaves as a PSGI application (subroutine reference). This is for the OAuth 2.0 token-endpoint.

The first thing you need to do is make your custom class, which inherits OAuth::Lite2::Server::DataHandler, and then setup the PSGI file referencing it.

## METHODS

### new( %params )

- data\_handler

  The name of your custom class that inherits the OAuth::Lite2::Server::DataHandler package.

- error\_uri

  Optional. This URI indicates the page that should be presented on an error. This will be included in error responses.

### support\_grant\_type( $type )

Indicates support for a specific grant type. This does not remove previously supported grant types. The available values are:

- authorization\_code

  - password

  - client\_credentials

  - refresh\_token

  ### support\_grant\_types( @types )

Allows specification of multiple grant types at once. This is equivalent to calling support\_grant\_type once for each type in the list. The available values are:

- authorization\_code

  - password

  - client\_credentials

  - refresh\_token

  ### data\_handler

This returns the class that inherits the OAuth::Lite2::Server::DataHandler package. This is defined by the data\_handler parameter of the constructor.

### psgi\_app

This returns a PSGI application.

### compile\_psgi\_app

This will compile the PSGI application.

### handle\_request( $req )

This will parse the access token request and call the data handler's method.

## TEST

You can test with OAuth::Lite2::Agent::PSGIMock and some of the client classes.

```
    my $app = OAuth::Lite2::Server::Endpoint::Token->new(
        data_handler => 'MyDataHandlerClass',
    );
    $app->support_grant_types(qw(authorization_code refresh_token));
    my $mock_agent = OAuth::Lite2::Agent::PSGIMock->new(app => $app);
    my $client = OAuth::Lite2::Client::UsernameAndPassword->new(
        id     => q{my_client_id},
        secret => q{my_client_secret},
        agent  => $mock_agent,
    );
    my $token = $client->get_access_token(
        username => q{foo},
        password => q{bar},
    );
    ok($token);
    is($token->access_token, q{access_token_value});
```

## AUTHOR

Ryo Ito, \<ritou.06@gmail.com\>

Lyo Kato, \<lyo.kato@gmail.com\>

## COPYRIGHT AND LICENSE

Copyright (C) 2010 by Lyo Kato

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
