Skip to content

Commit

Permalink
Merge pull request #1 from SWINGeV/develop
Browse files Browse the repository at this point in the history
Add Azure provider
  • Loading branch information
rhukster committed Mar 12, 2020
2 parents 1c81216 + df6325f commit fac77e2
Show file tree
Hide file tree
Showing 29 changed files with 2,080 additions and 4 deletions.
92 changes: 92 additions & 0 deletions blueprints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,96 @@ form:
type: display
style: vertical
content: '[<i class="fa fa-book"></i> Twitch OAuth2 from the official documentation](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/?target=_blank)'
markdown: true

azure:
type: fieldset
title: Azure
collapsible: true

fields:

azure_columns:
type: columns

fields:

azure_column_left:
type: column

fields:

azure.site:
type: display
style: vertical
content: '<h3>Site</h3>'

providers.azure.enabled:
type: toggle
label: Enabled
highlight: 1
default: 0
options:
1: Enabled
0: Disabled
validate:
type: bool

providers.azure.client_id:
type: text
label: PLUGIN_LOGIN_OAUTH2.CLIENT_ID

providers.azure.client_secret:
type: text
label: PLUGIN_LOGIN_OAUTH2.CLIENT_SECRET

providers.azure.options.scope:
type: selectize
size: large
label: PLUGIN_LOGIN_OAUTH2.SCOPE
classes: fancy
validate:
type: commalist

azure_column_right:
type: column

fields:

azure.admin:
type: display
style: vertical
content: '<h3>Admin</h3>'

admin.providers.azure.enabled:
type: toggle
label: Enabled
highlight: 1
default: 0
options:
1: Enabled
0: Disabled
validate:
type: bool

admin.providers.azure.client_id:
type: text
label: PLUGIN_LOGIN_OAUTH2.CLIENT_ID

admin.providers.azure.client_secret:
type: text
label: PLUGIN_LOGIN_OAUTH2.CLIENT_SECRET

admin.providers.azure.options.scope:
type: selectize
size: large
label: PLUGIN_LOGIN_OAUTH2.SCOPE
classes: fancy
validate:
type: commalist

providers.azure.description:
type: display
style: vertical
content: '[<i class="fa fa-book"></i> Quickstart: Register an application with the Microsoft identity platform](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app). Make sure you create a client secret for the authorization code flow.'
markdown: true
39 changes: 39 additions & 0 deletions classes/Providers/AzureProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
namespace Grav\Plugin\Login\OAuth2\Providers;

class AzureProvider extends ExtraProvider
{
protected $name = 'Azure';
protected $classname = 'TheNetworg\\OAuth2\\Client\\Provider\\Azure';

public function initProvider(array $options)
{
$options += [
'clientId' => $this->config->get('providers.azure.client_id'),
'clientSecret' => $this->config->get('providers.azure.client_secret'),
'redirectUri' => $this->getCallbackUri(),
];

parent::initProvider($options);
}

public function getAuthorizationUrl()
{
$options = ['state' => $this->state];
$options['scope'] = $this->config->get('providers.azure.options.scope');

return $this->provider->getAuthorizationUrl($options);
}

public function getUserData($user)
{
$data_user = [
'id' => $user->getId(),
'login' => $user->getUpn(),
'fullname' => $user->getFirstName() . " " . $user->getLastName(),
'email' => $user->getUpn()
];

return $data_user;
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"adam-paterson/oauth2-slack": "^1.1",
"mrjoops/oauth2-jira": "^0.2.4",
"omines/oauth2-gitlab": "^3.1",
"depotwarehouse/oauth2-twitch": "^1.3"
"depotwarehouse/oauth2-twitch": "^1.3",
"thenetworg/oauth2-azure": "^1.4"
},
"replace": {
"league/oauth2-client": "*",
Expand Down
102 changes: 100 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions css/login-oauth2-extras.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@
background: #55368B;
}

.form-oauth2 button.azure {
background: #2F2F2F;
font-family: Segoe UI, Frutiger, Frutiger Linotype, Dejavu Sans, Helvetica Neue, Arial, sans-serif;
font-size: 15px;
font-weight: 600;
}
14 changes: 13 additions & 1 deletion login-oauth2-extras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ providers:
client_secret: ''
options:
scope: ['user_read']
azure:
enabled: false
client_id: ''
client_secret: ''
options:
scope: ['User.Read']

admin:
enabled: true
Expand Down Expand Up @@ -67,4 +73,10 @@ admin:
client_id: ''
client_secret: ''
options:
scope: ['user_read']
scope: ['user_read']
azure:
enabled: false
client_id: ''
client_secret: ''
options:
scope: ['User.Read']
1 change: 1 addition & 0 deletions media/azure.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions templates/login-oauth2/providers/azure.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<button name="oauth2" type="submit" value="azure" class="azure">
{% include('@oauth2-media/azure.svg') %}
<span>Sign in with Microsoft</span>
</button>
2 changes: 2 additions & 0 deletions vendor/composer/autoload_psr4.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

return array(
'Wohali\\OAuth2\\Client\\' => array($vendorDir . '/wohali/oauth2-discord-new/src'),
'TheNetworg\\OAuth2\\Client\\' => array($vendorDir . '/thenetworg/oauth2-azure/src'),
'Omines\\OAuth2\\Client\\' => array($vendorDir . '/omines/oauth2-gitlab/src'),
'Mrjoops\\OAuth2\\Client\\' => array($vendorDir . '/mrjoops/oauth2-jira/src'),
'Grav\\Plugin\\Login\\OAuth2\\' => array($baseDir . '/classes'),
'Firebase\\JWT\\' => array($vendorDir . '/firebase/php-jwt/src'),
'Depotwarehouse\\OAuth2\\Client\\Twitch\\' => array($vendorDir . '/depotwarehouse/oauth2-twitch/src'),
'AdamPaterson\\OAuth2\\Client\\' => array($vendorDir . '/adam-paterson/oauth2-slack/src'),
);
3 changes: 3 additions & 0 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public static function loadClassLoader($class)
}
}

/**
* @return \Composer\Autoload\ClassLoader
*/
public static function getLoader()
{
if (null !== self::$loader) {
Expand Down
16 changes: 16 additions & 0 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class ComposerStaticInit2bc173dc5f62569a5dcf95d262de45bd
array (
'Wohali\\OAuth2\\Client\\' => 21,
),
'T' =>
array (
'TheNetworg\\OAuth2\\Client\\' => 25,
),
'O' =>
array (
'Omines\\OAuth2\\Client\\' => 21,
Expand All @@ -23,6 +27,10 @@ class ComposerStaticInit2bc173dc5f62569a5dcf95d262de45bd
array (
'Grav\\Plugin\\Login\\OAuth2\\' => 25,
),
'F' =>
array (
'Firebase\\JWT\\' => 13,
),
'D' =>
array (
'Depotwarehouse\\OAuth2\\Client\\Twitch\\' => 36,
Expand All @@ -38,6 +46,10 @@ class ComposerStaticInit2bc173dc5f62569a5dcf95d262de45bd
array (
0 => __DIR__ . '/..' . '/wohali/oauth2-discord-new/src',
),
'TheNetworg\\OAuth2\\Client\\' =>
array (
0 => __DIR__ . '/..' . '/thenetworg/oauth2-azure/src',
),
'Omines\\OAuth2\\Client\\' =>
array (
0 => __DIR__ . '/..' . '/omines/oauth2-gitlab/src',
Expand All @@ -50,6 +62,10 @@ class ComposerStaticInit2bc173dc5f62569a5dcf95d262de45bd
array (
0 => __DIR__ . '/../..' . '/classes',
),
'Firebase\\JWT\\' =>
array (
0 => __DIR__ . '/..' . '/firebase/php-jwt/src',
),
'Depotwarehouse\\OAuth2\\Client\\Twitch\\' =>
array (
0 => __DIR__ . '/..' . '/depotwarehouse/oauth2-twitch/src',
Expand Down
Loading

0 comments on commit fac77e2

Please sign in to comment.