mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Microsoft oauth
This commit is contained in:
parent
e546d7348a
commit
8e7dc5fca4
@ -23,6 +23,7 @@ use App\Jobs\Util\SystemLogger;
|
|||||||
use App\Libraries\MultiDB;
|
use App\Libraries\MultiDB;
|
||||||
use App\Libraries\OAuth\OAuth;
|
use App\Libraries\OAuth\OAuth;
|
||||||
use App\Libraries\OAuth\Providers\Google;
|
use App\Libraries\OAuth\Providers\Google;
|
||||||
|
use App\Models\Account;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\CompanyToken;
|
use App\Models\CompanyToken;
|
||||||
@ -363,17 +364,18 @@ class LoginController extends BaseController
|
|||||||
if (request()->input('provider') == 'google') {
|
if (request()->input('provider') == 'google') {
|
||||||
return $this->handleGoogleOauth();
|
return $this->handleGoogleOauth();
|
||||||
} elseif (request()->input('provider') == 'microsoft') {
|
} elseif (request()->input('provider') == 'microsoft') {
|
||||||
if (request()->has('token')) {
|
// if (request()->has('token')) {
|
||||||
return $this->handleSocialiteLogin('microsoft', request()->get('token'));
|
// return $this->handleSocialiteLogin('microsoft', request()->get('token'));
|
||||||
} else {
|
// } else {
|
||||||
$message = 'Bearer token missing for the microsoft login';
|
// $message = 'Bearer token missing for the microsoft login';
|
||||||
}
|
// }
|
||||||
|
return $this->handleMicrosoftOauth();
|
||||||
} elseif (request()->input('provider') == 'apple') {
|
} elseif (request()->input('provider') == 'apple') {
|
||||||
if (request()->has('token')) {
|
// if (request()->has('token')) {
|
||||||
return $this->handleSocialiteLogin('apple', request()->get('token'));
|
// return $this->handleSocialiteLogin('apple', request()->get('token'));
|
||||||
} else {
|
// } else {
|
||||||
$message = 'Token is missing for the apple login';
|
// $message = 'Token is missing for the apple login';
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()
|
return response()
|
||||||
@ -483,6 +485,9 @@ class LoginController extends BaseController
|
|||||||
|
|
||||||
$cu = CompanyUser::query()->where('user_id', auth()->user()->id);
|
$cu = CompanyUser::query()->where('user_id', auth()->user()->id);
|
||||||
|
|
||||||
|
if($cu->count() == 0)
|
||||||
|
return $cu;
|
||||||
|
|
||||||
if (CompanyUser::query()->where('user_id', auth()->user()->id)->where('company_id', auth()->user()->account->default_company_id)->exists())
|
if (CompanyUser::query()->where('user_id', auth()->user()->id)->where('company_id', auth()->user()->account->default_company_id)->exists())
|
||||||
$set_company = auth()->user()->account->default_company;
|
$set_company = auth()->user()->account->default_company;
|
||||||
else {
|
else {
|
||||||
@ -521,6 +526,24 @@ class LoginController extends BaseController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function handleMicrosoftOauth()
|
||||||
|
{
|
||||||
|
if(request()->has('accessToken'))
|
||||||
|
$accessToken = request()->input('accessToken');
|
||||||
|
else
|
||||||
|
return response()->json(['message' => 'Invalid response from oauth server'], 400);
|
||||||
|
|
||||||
|
$graph = new Microsoft\Graph();
|
||||||
|
$graph->setAccessToken($accessToken);
|
||||||
|
|
||||||
|
$user = $graph->createRequest("GET", "/me")
|
||||||
|
->setReturnType(Microsoft\Graph\Model\User::class)
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
nlog($user);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private function handleGoogleOauth()
|
private function handleGoogleOauth()
|
||||||
{
|
{
|
||||||
$user = false;
|
$user = false;
|
||||||
@ -599,9 +622,6 @@ class LoginController extends BaseController
|
|||||||
|
|
||||||
$cu = $this->hydrateCompanyUser();
|
$cu = $this->hydrateCompanyUser();
|
||||||
|
|
||||||
// $cu = CompanyUser::query()
|
|
||||||
// ->where('user_id', auth()->user()->id);
|
|
||||||
|
|
||||||
if ($cu->count() == 0)
|
if ($cu->count() == 0)
|
||||||
return response()->json(['message' => 'User found, but not attached to any companies, please see your administrator'], 400);
|
return response()->json(['message' => 'User found, but not attached to any companies, please see your administrator'], 400);
|
||||||
|
|
||||||
@ -628,6 +648,9 @@ class LoginController extends BaseController
|
|||||||
|
|
||||||
$account = CreateAccount::dispatchNow($new_account, request()->getClientIp());
|
$account = CreateAccount::dispatchNow($new_account, request()->getClientIp());
|
||||||
|
|
||||||
|
if(!$account instanceOf Account)
|
||||||
|
return $account;
|
||||||
|
|
||||||
Auth::login($account->default_company->owner(), true);
|
Auth::login($account->default_company->owner(), true);
|
||||||
auth()->user()->email_verified_at = now();
|
auth()->user()->email_verified_at = now();
|
||||||
auth()->user()->save();
|
auth()->user()->save();
|
||||||
|
@ -71,6 +71,7 @@
|
|||||||
"league/fractal": "^0.17.0",
|
"league/fractal": "^0.17.0",
|
||||||
"league/omnipay": "^3.1",
|
"league/omnipay": "^3.1",
|
||||||
"livewire/livewire": "^2.6",
|
"livewire/livewire": "^2.6",
|
||||||
|
"microsoft/microsoft-graph": "^1.69",
|
||||||
"mollie/mollie-api-php": "^2.36",
|
"mollie/mollie-api-php": "^2.36",
|
||||||
"nelexa/zip": "^4.0",
|
"nelexa/zip": "^4.0",
|
||||||
"nwidart/laravel-modules": "8.3",
|
"nwidart/laravel-modules": "8.3",
|
||||||
|
53
composer.lock
generated
53
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "6845489fdc254427c4536e22f025ff51",
|
"content-hash": "df84a1903809a8e781d937e679821e74",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "afosto/yaac",
|
"name": "afosto/yaac",
|
||||||
@ -4928,6 +4928,57 @@
|
|||||||
],
|
],
|
||||||
"time": "2022-04-07T21:38:12+00:00"
|
"time": "2022-04-07T21:38:12+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "microsoft/microsoft-graph",
|
||||||
|
"version": "1.69.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/microsoftgraph/msgraph-sdk-php.git",
|
||||||
|
"reference": "dc867afdb2c89ea7ead37d6bcfcaf0389e7a85f4"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/microsoftgraph/msgraph-sdk-php/zipball/dc867afdb2c89ea7ead37d6bcfcaf0389e7a85f4",
|
||||||
|
"reference": "dc867afdb2c89ea7ead37d6bcfcaf0389e7a85f4",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-json": "*",
|
||||||
|
"guzzlehttp/guzzle": "^6.0 || ^7.0",
|
||||||
|
"php": "^8.0 || ^7.3",
|
||||||
|
"psr/http-message": "^1.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"mikey179/vfsstream": "^1.2",
|
||||||
|
"phpstan/phpstan": "^0.12.90 || ^1.0.0",
|
||||||
|
"phpunit/phpunit": "^8.0 || ^9.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Microsoft\\Graph\\": "src/",
|
||||||
|
"Beta\\Microsoft\\Graph\\": "src/Beta/Microsoft/Graph/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Microsoft Graph Client Tooling",
|
||||||
|
"email": "graphtooling@service.microsoft.com",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "The Microsoft Graph SDK for PHP",
|
||||||
|
"homepage": "https://developer.microsoft.com/en-us/graph",
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/microsoftgraph/msgraph-sdk-php/issues",
|
||||||
|
"source": "https://github.com/microsoftgraph/msgraph-sdk-php/tree/1.69.0"
|
||||||
|
},
|
||||||
|
"time": "2022-06-15T11:11:33+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "mollie/mollie-api-php",
|
"name": "mollie/mollie-api-php",
|
||||||
"version": "v2.44.1",
|
"version": "v2.44.1",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user