oauth2-microsoft icon indicating copy to clipboard operation
oauth2-microsoft copied to clipboard

Plans on using v2.0 endpoints

Open gvso opened this issue 6 years ago • 7 comments

I was trying to use the Microsoft Graph to get some extra data, but the authentication process of this library seems to get a token which is not valid for that purpose.

I was looking at the authentication process in the above website, and the urls are different from what this library uses, so I thought that the difference was caused by these changes. I have updated the code to allow authentication and data request from v2.0 endpoints. However, that would mean that the oauth2-azure should be integrated into this one if this library migrates to the new endpoints.

gvso avatar Mar 13 '18 14:03 gvso

Edit: 9th June 2018...

I have resolved the issue. I can now auth with a live account for a one drive storage device.

Login:

$provider = new \Stevenmaguire\OAuth2\Client\Provider\Microsoft([
	    'clientId'     				=> $this->appID,
	    'clientSecret' 				=> $this->appSecret,
	    'redirectUri'  				=> $this->redirectURL,
	    'urlAuthorize'              => 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
		'urlAccessToken'            => 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
	    'urlResourceOwnerDetails'   => 'https://outlook.office.com/api/v2.0/me'
	]);

	$options = [		    
		'scope' => ['offline_access https://graph.microsoft.com/files.read']
	];

	$url = $provider->getAuthorizationUrl($options);

Auth:

$provider = new \Stevenmaguire\OAuth2\Client\Provider\Microsoft([
	    'clientId'     				=> $this->appID,
	    'clientSecret' 				=> $this->appSecret,
	    'redirectUri'  				=> $this->redirectURL,
	    'urlAuthorize'              => 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
		'urlAccessToken'            => 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
	    'urlResourceOwnerDetails'   => 'https://outlook.office.com/api/v2.0/me'
	]);

	// Get Token
	$token = $provider->getAccessToken('authorization_code', [
        'code' => $data['code']
    ]);  

    $refreshToken = $token->getRefreshToken();
    $tokenExpires = $token->getExpires();
    $token = trim($token->getToken());	    			

I have not tested whether the resource works. I don't need it for this use case.

paulm17 avatar Mar 25 '18 13:03 paulm17

I think the new API will need a new provider for one line of code. You can use the generic provider and add this: https://stackoverflow.com/questions/47741865/microsoft-graph-keeps-raising-invalidargumentexception

I did it manually, and it is working now. I was getting an invalid_grant before and I am now getting the user bits.

cbasolutions avatar Mar 25 '18 21:03 cbasolutions

I am leaning towards updating this package to support the entire array of OAuth 2 patterns available by Microsoft (login.live.com, graph.microsoft.com, login.microsoftonline.com); I don't think it will be difficult to do. I am not a heavy Microsoft API consumer, so what I would like to ask is for some help from one of you fine folks to test out a beta branch of this library and help dial in the requirements and the behavior.

@GVSO, @paulm17, @cbasolutions either of you up for that?

stevenmaguire avatar Mar 27 '18 01:03 stevenmaguire

I can help with some testing if necessary. I'm not a Microsoft API consumer though. Also, I can ask people to test and report things if needed when using Social Auth Microsoft

gvso avatar Mar 27 '18 02:03 gvso

@stevenmaguire I can also help with tests.

hint: check BearerAuthorizationTrait ;-)

ernestwisniewski avatar Nov 28 '18 22:11 ernestwisniewski

Thanks for your patience on this. Unfortunately for this project, I have been investing my OSS time elsewhere lately. I did begin this process in the Spring and it is still unfinished. I am happy to push up the branch and ask you all for help here. If you would like to take a run at updating the package to offer a bit more broad support I will gladly welcome the help.

stevenmaguire avatar Nov 28 '18 22:11 stevenmaguire

FYI there's a fork of this project which works with the new endpoints and is published on Packagist: Trunkstar/oauth2-microsoft.

rimas-kudelis avatar Nov 14 '23 14:11 rimas-kudelis