stevenmaguire / oauth2-microsoft

Microsoft OAuth 2.0 support for the PHP League's OAuth 2.0 Client
MIT License
66 stars 41 forks source link

Bad Request in stevenmaguire\oauth2-microsoft\src\Provider\Microsoft.php:79 #14

Open laurelBE opened 6 years ago

laurelBE commented 6 years ago

how to use provider, currently my code is as follows

$provider = new \Stevenmaguire\OAuth2\Client\Provider\Microsoft([ 'clientId' => $clientId, 'clientSecret' => $clientSecret, 'redirectUri' => 'none', ]);

It gives error as below

#0 C:\inetpub\wwwroot\bephpforTteam\New\vendor\league\oauth2-client\src\Provider\AbstractProvider.php(613):
Stevenmaguire\OAuth2\Client\Provider\Microsoft->checkResponse(Object(GuzzleHttp\Psr7\Response), Array)
simon511000 commented 6 years ago

Up

chrisforrence commented 6 years ago

Well, the redirectUri is important; if it doesn't match a/the callback on the Microsoft app side of things, the request will get rejected. It's essentially used to make sure that the OAuth2 request will end up going to a known URL instead of an arbitrary one, since there will be sensitive data in the URL.

For more information: https://www.oauth.com/oauth2-servers/redirect-uris/

ander1980 commented 4 years ago

Gostaria de contribuir,

Caso não tenha conta empresarial da microsoft, essa rotina funciona com contas de emails comuns usando o login live.com:

$provider = new Stevenmaguire\OAuth2\Client\Provider\Microsoft([ // Required 'clientId' => '{seu cliente-id na conta da Azure.', 'clientSecret' => 'seu cliente-secret gerado na Azure', 'redirectUri' => 'seu link de retorno, deve estar idêntico à conta da Azure',

    'urlAuthorize'              => 'https://login.live.com/oauth20_authorize.srf',
    'urlAccessToken'            => 'https://login.live.com/oauth20_token.srf',
    //'urlResourceOwnerDetails'   => 'https://login.live.com/' //Deprecated 
]);

É necessário criar as definições de sua aplicação na conta da Azure em: https://portal.azure.com/#home Localize -> Serviços de aplicativos ->Gerenciar o Azure Active Diretory Localize -> Registros de Aplicativos na barra lateral. Crie seu novo registro de aplicativo, client-id, client-secret, permitir tokens de acesso, etc.