Giter Site home page Giter Site logo

microsoft / kiota-authentication-phpleague-php Goto Github PK

View Code? Open in Web Editor NEW
5.0 17.0 4.0 182 KB

Kiota authentication provider implementation for OAuth with PHPLeague

Home Page: https://aka.ms/kiota/docs

License: MIT License

PHP 100.00%
kiota oauth php phpleague

kiota-authentication-phpleague-php's Introduction

Kiota Authentication Provider Library for PHP

Build Status Latest Stable Version Coverage

The Kiota Authentication provider library for PHP uses the PHP League OAuth 2.0 client to authenticate against the Microsoft Identity platform.

A Kiota generated project will need a reference to a authentication provider library to authenticate HTTP requests to an API endpoint.

Read more about Kiota here.

Using the Kiota Authentication Provider Library for PHP

run composer require microsoft/kiota-authentication-phpleague or add the following to your composer.json file:

{
    "require": {
        "microsoft/kiota-authentication-phpleague": "^1.1.0"
    }
}

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

kiota-authentication-phpleague-php's People

Contributors

adrienbrault avatar andrueastman avatar baywet avatar dependabot[bot] avatar ndiritu avatar robertbaelde avatar silaskenneth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kiota-authentication-phpleague-php's Issues

Fix potential identity swapping in async scenarios

This lib currently caches access tokens in memory. Building on the work in #18 which abstracts the token caching layer while defaulting to an in-memory cache, a potential bug was identified.

PHP largely uses a single-process per request but using asynchronous programming frameworks like Swoole could present cases where two threads handling different user's requests could read the same cached token leading to an identity swap. This is if the same authentication provider is injected

Discussed solution is to cache tokens in a way that retrieval is unique to a user for delegated auth scenarios and unique to a tenant and client for application permission scenarios. Cached tokens to be stored/retrieved in/from a map with the following keys:

  • tenantId-clientId-userId - delegated permissions
  • tenantId-clientId - application permissions

ToDo

AuthorizationUrl is not correct

Hello,

I am trying to upgrade my application to use msgraph-sdk-php v2 and found this issue in this package.

$tokenRequestContext = new AuthorizationCodeContext(
    'tenantId', 'clientId', 'clientSecret', 'authCode', 'redirectUri');

$scopes = ['User.Read'];
$authProvider = new GraphPhpLeagueAuthenticationProvider($tokenRequestContext, $scopes);
$redirectUrl = $authProvider->getAccessTokenProvider()
    ->getOauthProvider()->getAuthorizationUrl();

The authorization url is not correct because of:

  1. AADSTS900144: The request body must contain the following parameter: 'client_id'.
  2. AADSTS900144: The request body must contain the following parameter: 'scope'.
  3. Also the redirectUri is missing, there is no specific error for this, but it is necessary.

The clientId and redirectId issues could be fixed in the ProviderFactory class when creating the GenericProvider.
The scopes issue could be fixed in the PhpLeagueAccessTokenProvider constructor and pass them to the ProviderFactory::create, and then to the GenericProvider.

The goal is to have the League\OAuth2\Client\Provider\GenericProvider class fully equipped, which might also require passing the clientSecret to it, but it is not necessary for getAuthorizationUrl().

I can imagine that this fix might not be as simple as I described, but if you could look into it, it would be greatly appreciated.

Thanks!

PHP - Enhance auth support

Initial PHP auth provider PR microsoft/kiota#1201 adds basic support for client_credentials & auth code flows

Consider adding support for:.

  • Device Code flow
  • OIDC capabilities (sign out, token validation, token introspection ...)

Missing options in oauth provider

ClientId, ClientSecret and additional parameters are not persisted in oauth provider https://github.com/microsoft/kiota-authentication-phpleague-php/blob/dev/src/Oauth/ProviderFactory.php#L32

Consider the following example

$tenantId = '';
$clientId = '';
$clientSecret = '';

$clientCredentials = new ClientCredentialContext($tenantId, $clientId, $clientSecret);

$accessTokenProvider = new PhpLeagueAccessTokenProvider($clientCredentials);
$accessTokenProvider->getOauthProvider()->authorize(); 

Result: The request body must contain the following parameter: 'client_id'.

https://login.microsoftonline.com/{$tenantId}/oauth2/v2.0/authorize?state=randomstring&response_type=code&approval_prompt=auto

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.