StartZ oauth2-etsy compatible League of PHP OAuth2

Overview

Etsy Provider for OAuth 2.0 Client

GitHub tag GitHub license build codecov Packagist Downloads

This package provides Etsy OAuth 2.0 support for the PHP League's OAuth 2.0 Client.

Requirements

The following versions of PHP are supported.

  • PHP 7.3
  • PHP 7.4
  • PHP 8.0

Installation

To install, use composer:

composer require startz/oauth2-etsy

Usage

Usage is the same as The League's OAuth client, using \StartZ\OAuth2\Client\Provider\Etsy as the provider.

Please refer to your Etsy Developer Account for the necessary settings.

Authorization Code Flow

<?php

session_start();

require_once __DIR__ . '/vendor/autoload.php';

$provider = new Startz\OAuth2\Client\Provider\Etsy([
    'clientId'     => '{etsy-apikey-keystring}',
    'clientSecret' => '{etsy-apikey-shared-secret}',
    'redirectUri'  => 'https://example.com/callback-url',
]);

if ( ! isset($_GET['code'])) 
{
    // If we don't have an authorization code then get one
    $preChallenge = $provider->getPreChallenge();
    $authUrl = $provider->getAuthorizationUrl([
        'code_challenge' => $provider->getPKCE($preChallenge),
        'code_challenge_method' => 'S256'
    ]);
    $_SESSION['oauth2state'] = $provider->getState();
    $_SESSION['oauth2code'] = $preChallenge;
    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']);
    unset($_SESSION['oauth2code']);
    exit('Invalid state');

} else {
    
    $preChallenge = $_SESSION['oauth2code'];
    $authParams = [
        'code' => $_GET['code'],
        'code_verifier' => $preChallenge,
    ];
    // Try to get an access token (using the authorization code grant)
    $token = $provider->getAccessToken('authorization_code', $authParams);

    // 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);
        printf('Hello %s!', $user->getName());

    } catch (Exception $e) {

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

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

Testing

Unit Tests

$ ./vendor/bin/phpunit

Code Sniff

$ ./vendor/bin/phpcs src --standard=psr2 -sp
You might also like...
A One Time Password Authentication package, compatible with Google Authenticator.
A One Time Password Authentication package, compatible with Google Authenticator.

Google2FA Google Two-Factor Authentication for PHP Google2FA is a PHP implementation of the Google Two-Factor Authentication Module, supporting the HM

Cliente OAuth2 para Gov.br

Cliente OAuth2 para Gov.br Este pacote fornece suporte OAuth 2.0 para Gov.br usando a biblioteca cliente do League PHP. Requisitos Versões suportadas

This is a basic Oauth2 authorization/authentication server implemented using Mezzio.
This is a basic Oauth2 authorization/authentication server implemented using Mezzio.

Mezzio-OAuth2-Authorization-Authentication-Server This is a basic OAuth2 authorization/authentication server implemented using Mezzio. I have found so

A plugin for implementing an OAuth2 server in CakePHP 3

OAuth2 Server for CakePHP 3 A plugin for implementing an OAuth2 server in CakePHP 3. Built on top of the PHP League's OAuth2 Server. Currently we supp

Static utilitiy classes to bridge PSR-7 http messages to OAuth2 Server requests and responses.

Static utilitiy classes to bridge PSR-7 http messages to OAuth2 Server requests and responses. While this libray is entended for use with Slim 3, it should work with any PSR-7 compatible framework.

This plugin integrates OAuth2 functionality into Guzzle Bundle

Guzzle Bundle OAuth2 Plugin This plugin integrates OAuth2 functionality into Guzzle Bundle, a bundle for building RESTful web service clients. Prerequ

Routes and Middleware for Using OAuth2 Server within a Slim Framework API

Chadicus\Slim\OAuth2 A collection of OAuth2 Server routes, middleware and utilities for use within a Slim 3 Framework API Requirements Chadicus\Slim\O

Laravel Passport is an OAuth2 server and API authentication package that is simple and enjoyable to use

Introduction Laravel Passport is an OAuth2 server and API authentication package that is simple and enjoyable to use. Official Documentation Documenta

Releases(0.0.2)
  • 0.0.2(Sep 15, 2022)

    Since The PHP League code will not be ready for a week or two, I have added some PKCE support. There will likely be some backward compatibility issues when the later version is released, but I will document it.

    Change Log

    • adding PKCE support as manual options
    • updating to the correct open API URL for Etsy v3
    Source code(tar.gz)
    Source code(zip)
  • 0.0.1(Sep 14, 2022)

    This is the initial release of Etsy Provider for OAuth 2.0 Client extending the PHP Leagues OAuth2 code.

    This is still waiting for the release of PKCE support by the Leagues OAuth client. The support was just written, now we are waiting for release.

    See: https://github.com/thephpleague/oauth2-client/pull/901

    Source code(tar.gz)
    Source code(zip)
Owner
StartZ
StartZ
Discord-oauth2 - At the end of oAuth2, which I have been researching and reading for a long time,

Discord-oauth2 - At the end of oAuth2, which I have been researching and reading for a long time, I finally found the way to connect with discord and get information, that's how I did it. If I'm wrong, feel free to email me so I can correct it.

Uğur Mercan 2 Jan 1, 2022
:atom: Social (OAuth1\OAuth2\OpenID\OpenIDConnect) sign with PHP :shipit:

SocialConnect Auth Getting Started :: Documentation :: Demo Open source social sign on PHP. Connect your application(s) with social network(s). Code e

SocialConnect 516 Nov 24, 2022
documentation for the oauth2-server-php library

OAuth2 Server PHP Documentation This repository hosts the documentation for the oauth2-server-php library. All submissions are welcome! To submit a ch

Brent Shaffer 227 Nov 24, 2022
:atom: Social (OAuth1\OAuth2\OpenID\OpenIDConnect) sign with PHP :shipit:

SocialConnect Auth Getting Started :: Documentation :: Demo Open source social sign on PHP. Connect your application(s) with social network(s). Code e

SocialConnect 458 Apr 1, 2021
EvaOAuth provides a standard interface for OAuth1.0(a) / OAuth2.0 client authorization, it is easy to integrate with any PHP project by very few lines code.

EvaOAuth EvaOAuth provides a standard interface for OAuth1.0 / OAuth2.0 client authorization, it is easy to integrate with any PHP project by very few

AlloVince 256 Nov 16, 2022
EvaOAuth provides a standard interface for OAuth1.0(a) / OAuth2.0 client authorization, it is easy to integrate with any PHP project by very few lines code.

EvaOAuth EvaOAuth provides a standard interface for OAuth1.0 / OAuth2.0 client authorization, it is easy to integrate with any PHP project by very few

AlloVince 261 Jan 17, 2022
Single Sign-On for PHP (Ajax compatible)

Single Sign-On for PHP (Ajax compatible) Jasny SSO is a relatively simply and straightforward solution for single sign on (SSO). With SSO, logging int

Arnold Daniels 1.4k Nov 29, 2022
Social (OAuth1\OAuth2\OpenID\OpenIDConnect) sign with PHP

Open source social sign on PHP. Connect your application(s) with social network(s).

SocialConnect 516 Nov 24, 2022
:octocat: Socialite is an OAuth2 Authentication tool. It is inspired by laravel/socialite, you can easily use it without Laravel.

Socialite Socialite is an OAuth2 Authentication tool. It is inspired by laravel/socialite, You can easily use it in any PHP project. 中文文档 This tool no

安正超 1.2k Nov 21, 2022
OAuth client integration for Symfony. Supports both OAuth1.0a and OAuth2.

HWIOAuthBundle The HWIOAuthBundle adds support for authenticating users via OAuth1.0a or OAuth2 in Symfony. Note: this bundle adds easy way to impleme

Hardware Info 2.2k Nov 11, 2022