Giter Site home page Giter Site logo

oauth2-client's Introduction

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

Laravel OAuth2 - Client

This Package can be used to connect to an OAuth2-Service and fetch OAuth2 restricted resources. this is Laravel OAuth rapper for https://github.com/adoy/PHP-OAuth2

1. Installation

via Composer

Update your composer.json "require"-Section with this line:

    
    "mahfuz05/laravel-oauth2": "dev-master"
    

After adding this line, run the following command:

    
    composer install
    or
    composer update
    

2. Configuration

You need to publish the configuration file of this package with:

    
    php artisan config:publish  mahfuz05/laravel-oauth2
    

The Config-File path is app/config/mahfuz05/laravel-oauth2/config.php

Here you have to add/modify the values for your purpose.
[client.id] - Client-ID of your Application
[client.secret] - Client-Secret of your Application
[scopes] - Scopes for your Application (comma separated)

After modifying the Package-Config, update the app/config/app.php
Modify your providers and aliases section, with your preferred alias:

<code><b>'providers' => 'Mahfuz05\LaravelOauth2\LaravelOauth2ServiceProvider'</b></code>
<br>
<code><b>'aliases' => 'LaravelOauth2'	=> 'Mahfuz05\LaravelOauth2\Facades\LaravelOauth2'</b></code>

3. Examples

Fetch Access-Token

    
    
    LaravelOauth2::fetchAccessToken('http://3rd.party.com/api/access_token', 'password', array(
        'username'	=> $credentials['username'],
        'password'	=> $credentials['password'],
        'scope'		=> Config::get('oauth2-client::scopes'),
    ));
    
    

Requesting a OAuth2 - Restricted Resource/URL

    
    
    $result = LaravelOauth2::fetch('http://3rd.party.com/api/restriced/resource');
    
    

Or you can use like this

      
            if (!isset($_GET['code']))
            {
                
                $auth_url = LaravelOauth2::getAuthenticationUrl($this->url, $this->redirectUri);
                header('Location: ' . $auth_url);
                die('Redirect');
            }
            else
            {
                $params = array('code' => $_GET['code'], 'redirect_uri' => $this->redirectUri);
                
                $response = LaravelOauth2::getAccessToken($this->token_url, 'authorization_code', $params);
    
                //get Access Token and store it
                
                LaravelOauth2::setAccessToken($response['result']['access_token']);
                $token = $response['result']['access_token'];
    
                //get all customers
    
                $response = LaravelOauth2::fetch('https://api.debitoor.com/api/v1.0/customers');
            }    

4. Constants

Auth methods

  • AUTH_TYPE_URI
  • AUTH_TYPE_AUTHORIZATION_BASIC
  • AUTH_TYPE_FORM

Access token types

  • ACCESS_TOKEN_URI
  • ACCESS_TOKEN_BEARER
  • ACCESS_TOKEN_OAUTH
  • ACCESS_TOKEN_MAC

Grant types

  • GRANT_TYPE_AUTH_CODE
  • GRANT_TYPE_PASSWORD
  • GRANT_TYPE_CLIENT_CREDENTIALS
  • GRANT_TYPE_REFRESH_TOKEN

HTTP Methods

  • HTTP_METHOD_GET
  • HTTP_METHOD_POST
  • HTTP_METHOD_PUT
  • HTTP_METHOD_DELETE
  • HTTP_METHOD_HEAD
  • HTTP_METHOD_PATCH

HTTP Form content types

  • HTTP_FORM_CONTENT_TYPE_APPLICATION
  • HTTP_FORM_CONTENT_TYPE_MULTIPART

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.