2017 © Pedro Peláez
 

library oauth2-azure

Oauth2 Azure login

image

vinhhoang/oauth2-azure

Oauth2 Azure login

  • Wednesday, November 8, 2017
  • by vinhhd
  • Repository
  • 2 Watchers
  • 0 Stars
  • 92 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 16 % Grown

The README.md

Oauth2 Azure login

This package is built based on this source Azure Active Directory Provider for OAuth 2.0 Client., (*1)

Installation

To install, use composer:, (*2)

composer require vinhhoang/oauth2-azure

Configuration

After installing the Socialite library, register the VinhHoang\OAuth2\AzureServiceProvider in your config/app.php configuration file:, (*3)

'providers' => [
    // Other service providers...

    VinhHoang\OAuth2\AzureServiceProvider::class,
],

Also, add the Azure facade to the aliases array in your app configuration file:, (*4)

'Azure' =>  VinhHoang\OAuth2\Facades\Azure::class

Then, run this comment, (*5)

php artisan vendor:publish --provider="VinhHoang\OAuth2\AzureServiceProvider", (*6)

You will also need to add credentials for the OAuth services your application utilizes. These credentials should be placed in your config/oauth2azure.php configuration file:, (*7)

[
    'clientId'          => 'your-client-id',
    'clientSecret'      => 'your-client-secret',
    'redirectUri'       => 'your-redirect-uri',
    'tenant'            => 'your-tenant',
],

Basic Usage

<?php

namespace App\Http\Controllers;

use Azure;

class LoginController
{
    public function login()
    {
        return Azure::redirect();
    }

    public function handleCallback()
    {
        $token = Azure::getAccessToken('authorization_code', [
            'code' => $_GET['code'],
            'resource' => 'https://graph.windows.net',
        ]);

        try {
            // We got an access token, let's now get the user's details
              $me = Azure::get("me", $token);

        } catch (\Exception $e) {
            //
        }

        // Use this to interact with an API on the users behalf

        echo $token->getToken();
    }

    public function logout()
    {
        $redirect_url = "http://example.com";
        return redirect(Azure::getLogoutUrl($redirect_url));
    }
}

You will need to define routes to your controller methods:, (*8)

Route::get('login', 'LoginController@login');
Route::get('login/callback', 'LoginController@handleCallback');
Route::get('logout', 'LoginController@logout');

Resource Owner

With version 1.1.0 and onward, the Resource Owner information is parsed from the JWT passed in access_token by Azure Active Directory. It exposes few attributes and one function., (*9)

Example:, (*10)

$resourceOwner = Azure::getResourceOwner($token);
echo 'Hello, '.$resourceOwner->getFirstName().'!';

The exposed attributes and function are: - getId() - Gets user's object id - unique for each user - getEmail() - Gets user's email - unique for each user - getFirstName() - Gets user's first name - getLastName() - Gets user's family name/surname - getTenantId() - Gets id of tenant which the user is member of - getUpn() - Gets user's User Principal Name, which can be also used as user's e-mail address - claim($name) - Gets any other claim (specified as $name) from the JWT, full list can be found here, (*11)

The Versions

08/11 2017

dev-master

9999999-dev

Oauth2 Azure login

  Sources   Download

MIT

The Requires

 

by Vinh Hoang

php azure

06/09 2017

1.0.1

1.0.1.0

Oauth2 Azure login

  Sources   Download

MIT

The Requires

 

by Vinh Hoang

php azure