PHPackages                             stevenmaguire/oauth2-elance - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. stevenmaguire/oauth2-elance

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

stevenmaguire/oauth2-elance
===========================

Elance OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2.0.0(9y ago)068MITPHP

Since Aug 20Pushed 9y ago1 watchersCompare

[ Source](https://github.com/stevenmaguire/oauth2-elance)[ Packagist](https://packagist.org/packages/stevenmaguire/oauth2-elance)[ RSS](/packages/stevenmaguire-oauth2-elance/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (4)Used By (0)

Elance Provider for OAuth 2.0 Client
====================================

[](#elance-provider-for-oauth-20-client)

[![Latest Version](https://camo.githubusercontent.com/12223b4dcab7628e2c89a404c4b77df6d2ea52c5854c8325e58b979eaba9f7c2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f73746576656e6d6167756972652f6f61757468322d656c616e63652e7376673f7374796c653d666c61742d737175617265)](https://github.com/stevenmaguire/oauth2-elance/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/aab336e55ce3346cb29975f46712c86fdb7550fc76af866cf32e7a72f8ae3fe3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f73746576656e6d6167756972652f6f61757468322d656c616e63652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/stevenmaguire/oauth2-elance)[![Coverage Status](https://camo.githubusercontent.com/4ff000bfef00f14327bb159039409bb6e5998e165a86789b0b240b75943f43fa/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f73746576656e6d6167756972652f6f61757468322d656c616e63652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/stevenmaguire/oauth2-elance/code-structure)[![Quality Score](https://camo.githubusercontent.com/f0b607a894c0ad908fd5026325af98038fa966c116cbed5ff7f8ea28aa62b792/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f73746576656e6d6167756972652f6f61757468322d656c616e63652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/stevenmaguire/oauth2-elance)[![Total Downloads](https://camo.githubusercontent.com/a770a1a53bba558f9facf88094a6a2f8c2db254ed57d5e168c9647f85413aef8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73746576656e6d6167756972652f6f61757468322d656c616e63652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stevenmaguire/oauth2-elance)

This package provides Elance OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).

Installation
------------

[](#installation)

To install, use composer:

```
composer require stevenmaguire/oauth2-elance

```

Usage
-----

[](#usage)

Usage is the same as The League's OAuth client, using `\Stevenmaguire\OAuth2\Client\Provider\Elance` as the provider.

### Authorization Code Flow

[](#authorization-code-flow)

```
$provider = new Stevenmaguire\OAuth2\Client\Provider\Elance([
    'clientId'          => '{elance-client-id}',
    'clientSecret'      => '{elance-client-secret}',
    'redirectUri'       => 'https://example.com/callback-url'
]);

if (!isset($_GET['code'])) {

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl();
    $_SESSION['oauth2state'] = $provider->getState();
    header('Location: '.$authUrl);
    exit;

// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

    unset($_SESSION['oauth2state']);
    exit('Invalid state');

} else {

    // Try to get an access token (using the authorization code grant)
    $token = $provider->getAccessToken('authorization_code', [
        'code' => $_GET['code']
    ]);

    // Optional: Now you have a token you can look up a users profile data
    try {

        // We got an access token, let's now get the user's details
        $user = $provider->getResourceOwner($token);

        // Use these details to create a new profile
        printf('Hello %s!', $user->getId());

    } catch (Exception $e) {

        // Failed to get user details
        exit('Oh dear...');
    }

    // Use this to interact with an API on the users behalf
    echo $token->getToken();
}
```

#### Important note about the Elance API

[](#important-note-about-the-elance-api)

This package attempts to use the [/profiles/my](https://www.elance.com/q/api2/methods/profiles/my) API endpoint to populate the `ElanceResourceOwner` object. This attempt will be successful if the resource owner has a "Contractor Profile" on Elance. If the resource owner does not have a "Contractor Profile" the request for this information will result in a 404 response and the code example above will fail.

The request to `getAccessToken` will succeed regardless of "Contractor Profile" status.

### Refreshing a Token

[](#refreshing-a-token)

Once your application is authorized, you can refresh an expired token using a refresh token rather than going through the entire process of obtaining a brand new token. To do so, simply reuse this refresh token from your data store to request a refresh.

```
$grant = new \League\OAuth2\Client\Grant\RefreshToken();
$token = $provider->getAccessToken($grant, ['refresh_token' => $refreshToken]);
```

Testing
-------

[](#testing)

```
$ ./vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/stevenmaguire/oauth2-elance/blob/master/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Steven Maguire](https://github.com/stevenmaguire)
- [All Contributors](https://github.com/stevenmaguire/oauth2-elance/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/stevenmaguire/oauth2-elance/blob/master/LICENSE) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~262 days

Total

3

Last Release

3400d ago

Major Versions

0.1.0 → 1.x-dev2015-08-20

1.x-dev → 2.0.02017-01-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d9c05a30823ae19fc54aa4b4721a696c253f8dec10c7fd22d372cfdc0fcb36d?d=identicon)[stevenmaguire](/maintainers/stevenmaguire)

---

Top Contributors

[![stevenmaguire](https://avatars.githubusercontent.com/u/1851973?v=4)](https://github.com/stevenmaguire "stevenmaguire (9 commits)")

---

Tags

clientoauthoauth2authorizationauthorisationelance

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/stevenmaguire-oauth2-elance/health.svg)

```
[![Health](https://phpackages.com/badges/stevenmaguire-oauth2-elance/health.svg)](https://phpackages.com/packages/stevenmaguire-oauth2-elance)
```

###  Alternatives

[stevenmaguire/oauth2-keycloak

Keycloak OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1132.5M6](/packages/patrickbussmann-oauth2-apple)[mollie/oauth2-mollie-php

Mollie Provider for OAuth 2.0 Client

251.7M1](/packages/mollie-oauth2-mollie-php)[omines/oauth2-gitlab

GitLab OAuth 2.0 Client Provider for The PHP League OAuth2-Client

36721.5k13](/packages/omines-oauth2-gitlab)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
