View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Chris Weyl > GitHub-Authorization-0.001 > GitHub::Authorization



Annotate this POD

View/Report Bugs
Module Version: 0.001   Source  


GitHub::Authorization - Generate a GitHub OAuth2 non-web authorization token


This document describes version 0.001 of GitHub::Authorization - released March 16, 2013 as part of GitHub-Authorization.


    use GitHub::Authorization;

    my $token_info = get_gh_token(
        user     => 'RsrchBoy',
        password => '*****',
        scopes   => ['repo'],
        note     => 'test!',
    my $token      = $token_info->{token};

    # e.g.
    use Net::GitHub;
    my $gh = Net::GitHub->new(access_token => $token, ...);

    # ... or ...
    use Pithub;
    my $ph = Pithub->new(token => $token, ...);


There are a number of good packages on the CPAN to handle working with the GitHub API, but none that provide a (relatively) lightweight, straight-forward way to generate OAuth2 tokens.

This package implements the procedure described in GitHub Developer's Guide "Non-Web Application Flow" to create authorization tokens; that is, authorization tokens that can be stored, managed, reused and revoked without needing to store (or otherwise acquire) a user password.


We do not export anything by default; Sub::Exporter::Progressive is used here so you can either use plain-old Exporter or fancy-new Sub::Exporter syntax; whatever you desire or require.


This package uses and returns OAuth2 authorization tokens, and uses V3 of the GitHub API.

Legal Scopes

The formal list of supported scopes can be found at the GitHub OAuth API reference (note this list is taken almost verbatim from that page). If a scope appears there but not here, please file an issue against this package (as the author has likely not noticed it yet).


get_gh_token(user => Str, password => Str, ...)

NOTE: Validate your parameters! We do basic validation, but nothing strenuous.

We take 2 mandatory parameters (user and password), and can take several more optional ones:


On success...

A successful return from get_gh_token() will look something like this:

        app => {
            name => "test! (API)",
            url  => "",
        created_at => "2012-12-24T14:28:17Z",
        id         => xxxxxxx, # an integer > 0
        note       => "test!",
        note_url   => undef,
        scopes     => ["public_repo"],
        token      => "****************************************",
        updated_at => "2012-12-24T14:28:17Z",
        url        => "",

The token slot is probably the bit you want.

On failure/error...

On failure, we confess() our sins:

    Failed: 401/Unauthorized / Bad credentials ...

That is, we "confess" in Carp with the status code, status message, and the message returned from GitHub itself.


Returns a list of legal scope names. (See get_gh_token() doc for the list)


Returns true if the scope name given is a legal scope.


All of a user's GitHub authorization tokens can be viewed and revoked on their GitHub Applications account page.

Users may revoke tokens at any time through GitHub proper.


We instruct our user-agent (HTTP::Tiny in this case) to validate the remote server's certificate, as described in "SSL-SUPPORT" in HTTP::Tiny. (Essentially, using Mozilla::CA).

While this satisfies the "let's be cautious" alarms in the author's head, this may be too paranoid or not paranoid enough for you. If so, please file an issue or pull request and we'll work something out.


This package currently has no capabilities for deleting, altering, or otherwise doing anything with tokens outside of creating them.


Please see those modules/websites for more information related to this module.


The development version is on github at and may be cloned from git://


Please report any bugs or feature requests on the bugtracker website

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.


Chris Weyl <>


This software is Copyright (c) 2012 by Chris Weyl.

This is free software, licensed under:

  The GNU Lesser General Public License, Version 2.1, February 1999
syntax highlighting: