php - Outlook API - We received a bad request -
i'm following this tutorial , getting following message: sorry, we’re having trouble signing in. received bad request. miserably, microsoft isn't giving me other message.
edit: here code i'm using id's , passwords masked
home.php
<?php session_start(); require('oauth.php'); $loggedin = false; $redirecturi = 'http://localhost:9999/outlook_cal03/authorize.php'; ?> <html> <head> <title>php mail api tutorial</title> </head> <body> <?php if (!$loggedin) { ?> <!-- user not logged in, prompt login --> <p>please <a href="<?php echo oauthservice::getloginurl($redirecturi)?>">sign in</a> office 365 or outlook.com account.</p> <?php } else { ?> <!-- user logged in, here --> <p>hello user!</p> <?php } ?> </body> </html>
oauth.php
<?php class oauthservice { private static $clientid = "###################"; private static $clientsecret = "################"; private static $authority = "https://login.microsoftonline.com"; private static $authorizeurl = '/common/oauth2/v2.0/authorize?client_id=%1$s&redirect_uri=%2$s&response_type=code&scope=%3$s'; private static $tokenurl = "/common/oauth2/v2.0/token"; // app needs openid (for user's id info), , mail.read private static $scopes = array("openid", "https://outlook.office.com/mail.read"); public static function getloginurl($redirecturi) { $redirecturi = $redirecturi; // build scope string. multiple scopes separated // space $scopestr = implode(" ", self::$scopes); $loginurl = self::$authority.sprintf(self::$authorizeurl, self::$clientid, urlencode($redirecturi), urlencode($scopestr)); error_log("generated login url: ".$loginurl); return $loginurl; } } ?>
authorize.php
<?php session_start(); $auth_code = $_get['code']; ?> <p>auth code: <?php echo $auth_code ?></p>
my problems stemmed fact had failed register redirect url outlook, , it.
Comments
Post a Comment