Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#357 Added Microsoft365 (aka Office365 or Azure AD, login.microsofton… #378

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Yii Framework 2 authclient extension Change Log

- Bug #364: Use issuer claim from OpenID Configuration (radwouters)
- Enh: #367: Throw more specific `ClientErrorResponseException` when the response code in `BaseOAuth::sendRequest()` is a 4xx (rhertogh)

- Enh: #357: Added Microsoft365 (aka Office365 or Azure AD, login.microsoftonline.com) OAuth2 client.

2.2.14 November 18, 2022
------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/guide-ja/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ return [
- Google ([[yii\authclient\clients\Google|OAuth]] または [[yii\authclient\clients\GoogleHybrid|OAuth Hybrid]] で)
- [[yii\authclient\clients\LinkedIn|LinkedIn]]
- [[yii\authclient\clients\Live|Microsoft Live]]
- [[yii\authclient\clients\Microsoft365]].
- [[yii\authclient\clients\Twitter|Twitter]]
- [[yii\authclient\clients\VKontakte|VKontakte]]
- [[yii\authclient\clients\Yandex|Yandex]]
Expand Down
1 change: 1 addition & 0 deletions docs/guide-ru/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ return [
- Google (с помощью [[yii\authclient\clients\Google|OAuth]] и [[yii\authclient\clients\GoogleHybrid|OAuth Hybrid]]).
- [[yii\authclient\clients\LinkedIn|LinkedIn]].
- [[yii\authclient\clients\Live|Microsoft Live]].
- [[yii\authclient\clients\Microsoft365]].
- [[yii\authclient\clients\Twitter|Twitter]].
- [[yii\authclient\clients\VKontakte|VKontakte]].
- [[yii\authclient\clients\Yandex|Yandex]].
Expand Down
1 change: 1 addition & 0 deletions docs/guide-zh-CN/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ return [
- Google (通过 [[yii\authclient\clients\Google|OAuth]] 和 [[yii\authclient\clients\GoogleHybrid|OAuth Hybrid]]).
- [[yii\authclient\clients\LinkedIn|LinkedIn]].
- [[yii\authclient\clients\Live|Microsoft Live]].
- [[yii\authclient\clients\Microsoft365]].
- [[yii\authclient\clients\Twitter|Twitter]].
- [[yii\authclient\clients\VKontakte|VKontakte]].
- [[yii\authclient\clients\Yandex|Yandex]].
Expand Down
1 change: 1 addition & 0 deletions docs/guide/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Out of the box the following clients are provided:
- Google (via [[yii\authclient\clients\Google|OAuth]] and [[yii\authclient\clients\GoogleHybrid|OAuth Hybrid]]).
- [[yii\authclient\clients\LinkedIn|LinkedIn]].
- [[yii\authclient\clients\Live|Microsoft Live]].
- [[yii\authclient\clients\Microsoft365]].
- [[yii\authclient\clients\Twitter|Twitter]].
- [[yii\authclient\clients\VKontakte|VKontakte]].
- [[yii\authclient\clients\Yandex|Yandex]].
Expand Down
3 changes: 3 additions & 0 deletions src/assets/authchoice.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
.auth-icon.live {
background-position: 0 -272px;
}
.auth-icon.microsoft365 {
background-position: 0 -306px;
}

.auth-clients {
display: block;
Expand Down
Binary file modified src/assets/authchoice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 107 additions & 0 deletions src/clients/Microsoft365.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/

namespace yii\authclient\clients;

use yii\authclient\OAuth2;

/**
* Microsoft365 allows authentication via Microsoft365 (aka Office365 or Azure AD) OAuth2 Organizations endpoints.
*
* Before using Microsoft365 OAuth2 you must register your App on the Microsoft Azure Portal <https://portal.azure.com>
*
* Note: the registered App must have the following:
* -Authentication: set the 'Redirect URIs' e.g. 'site/auth?authclient=microsoft365' as an absolute URL e.g. https://domain.com/index.php/site/auth?authclient=microsoft365
* -API Permissions: 'Microsoft Graph' > 'User.Read'
* -Decide whether the App should be single-tenant (only allow your own Microsoft Tenant to use it) or multi-tenant (allow any other Microsoft Tenants to use it)
*
* Example application configuration:
*
* ```php
* 'components' => [
* 'authClientCollection' => [
* 'class' => 'yii\authclient\Collection',
* 'clients' => [
* 'microsoft365' => [
* 'class' => 'yii\authclient\clients\Microsoft365',
* 'clientId' => 'a5e19acd-dc50-4b0a-864a-d13b9347ddf9',
* 'clientSecret' => 'ljSAd89.lvk34NV-3t4v3_2kl_42Rt4klr234',
* ],
* ],
* ]
* // ...
* ]
* ```
*
* @see https://portal.azure.com
* @see https://learn.microsoft.com/en-us/power-apps/developer/data-platform/walkthrough-register-app-azure-active-directory
* @see https://learn.microsoft.com/en-us/graph/use-the-api
*
* @author Enrico De Gaudenzi <enrico@degaudenzi.eu>
* @since 2.2.15
*/
class Microsoft365 extends OAuth2
{
/**
* {@inheritdoc}
*/
public $authUrl = 'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize';
/**
* {@inheritdoc}
*/
public $tokenUrl = 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token';
/**
* {@inheritdoc}
*/
public $apiBaseUrl = 'https://graph.microsoft.com/v1.0';


/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
if ($this->scope === null) {
$this->scope = implode(' ', [
'User.Read',
]);
}
}

/**
* {@inheritdoc}
*/
protected function initUserAttributes()
{
return $this->api('me', 'GET');
}

/**
* {@inheritdoc}
*/
public function applyAccessTokenToRequest($request, $accessToken)
{
$request->headers->set('Authorization', 'Bearer '.$accessToken->getToken());
}

/**
* {@inheritdoc}
*/
protected function defaultName()
{
return 'microsoft365';
}

/**
* {@inheritdoc}
*/
protected function defaultTitle()
{
return 'Microsoft365';
}
}
Loading