So far I have managed to successfully use the demo app to Connect to an Office365 Account, use the Microsoft Login page and sign in with the account and send the test email.... All perfect.
When I have tried to implement the code in my own app, I'm having trouble getting the access token.
It would appear that the response to the request for the Authorization Token returns a second login page.
The example app, with the same configuration variables returns a parsed array from the API, but when copied into my own application, the request returns a login screen.
As there is no specific error message from the Microsoft API (its just a login page) it is very difficult to debug. The exception that is thrown is AbstractProvider::prepareAccessTokenResponse() must be of the type array, string given, called in php myproject\vendor\league\oauth2-client\src\Provider\AbstractProvider.php on line 52
<!DOCTYPE html>
<html dir="ltr" class="" lang="en">
<head>
<title>Sign in to your account</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<meta name="PageID" content="ConvergedError" />
<meta name="SiteID" content="" />
<meta name="ReqLC" content="1033" />
<meta name="LocLC" content="en-US" />
<noscript>
<meta http-equiv="Refresh" content="0; URL=" />
</noscript>
<link rel="shortcut icon" href="https://secure.aadcdn.microsoftonline-p.com/ests/2.1.7758.23/content/images/favicon_a.ico" />
<meta name="robots" content="none" />
<script type="text/javascript">//<![CDATA[
$Config={"strHeaderText":"Sign in","unsafe_strTopMessage":"Sorry, but we’re having trouble signing you in.","strMainMessage":"We received a bad request.","strAdditionalMessage":"","strServiceExceptionMessage":"AADSTS90056: This endpoint only accepts POST, OPTIONS requests. Received a GET request.","strTraceId":"d8444ef7-293f-4057-8975-0bc8bc3d0500","strErrorCode":90056,"iHttpErrorCode":400,"iViewId":1,"urlCancel":"","strTimestamp":"2018-06-14T07:59:37Z","iMaxStackForKnockoutAsyncComponents":10000,"strCopyrightTxt":"\u0026#169;2018 Microsoft","fShowButtons":true,"fShowDogfoodBanner":false,"urlCdn":"https://secure.aadcdn.microsoftonline-p.com/ests/2.1.7758.23/","urlFooterTOU":"https://www.microsoft.com/en-US/servicesagreement/","urlFooterPrivacy":"https://privacy.microsoft.com/en-US/privacystatement","iPawnIcon":0,"sPOST_Username":"","sFTName":"flowToken","dynamicTenantBranding":null,"oAppCobranding":{},"iBackgroundImage":0,"fUseConstantPolling":true,"fUseFlowTokenAsCanary":true,"fApplicationInsightsEnabled":false,"iApplicationInsightsEnabledPercentage":0,"fRepositionFooterButtons":false,"fUseTextOnlyIdentityBannerWithBack":false,"fUseSigninSubtitle":false,"urlSetDebugMode":"https://login.microsoftonline.com/common/debugmode","scid":1013,"hpgact":1801,"hpgid":1117,"pgid":"ConvergedError","apiCanary":"AQABAAAAAADX8GCi6Js6SK82TsD2Pb7rjSZZBBLpcZL6aajP1EU2xivzJcl9J0-eWJzy_zyynpM-ibdfeiLggakoCmAkSnvrnaP1VRq39cjRQ2j5DuysRvda2Q-BQT7k_TSKc5gWFIyZbdc46n-JN47VCaCWh4ehtQvQg-6Ix6rdjFVdtaap_HjzFZrNaGaNJypJ1_s9yBX2OA2yFpWflYa5X_i4_zoqPKvLFhGs7o4Ym2hKYFV2CSAA","canary":"ALkDT++Ytaso98LIv/oFsy2Lt01LVvEDmMialCkKuxk=5:1","correlationId":"758e8d24-758c-4e97-a8ac-12198d9f1886","sessionId":"d8444ef7-293f-4057-8975-0bc8bc3d0500","locale":{"mkt":"en-US","lcid":1033},"slMaxRetry":2,"slReportFailure":true,"strings":{"desktopsso":{"authenticatingmessage":"Trying to sign you in"}},"enums":{"ClientMetricsModes":{"None":0,"SubmitOnPost":1,"SubmitOnRedirect":2,"InstrumentPlt":4}},"urls":{"instr":{"pageload":"https://login.microsoftonline.com/common/instrumentation/reportpageload","dssostatus":"https://login.microsoftonline.com/common/instrumentation/dssostatus"}},"browser":{"ltr":1,"_Other":1,"Full":1,"RE_Other":1,"b":{"name":"Other","major":-1,"minor":-1},"os":{"name":"Unknown","version":""},"V":-1},"watson":{"url":"/common/handlers/watson","bundle":"https://secure.aadcdn.microsoftonline-p.com/ests/2.1.7758.23/content/cdnbundles/watson.min.js","sbundle":"https://secure.aadcdn.microsoftonline-p.com/ests/2.1.7758.23/content/cdnbundles/watsonsupport.min.js","fbundle":"https://secure.aadcdn.microsoftonline-p.com/ests/2.1.7758.23/content/cdnbundles/frameworksupport.min.js","resetErrorPeriod":5,"maxCorsErrors":-1,"maxInjectErrors":5,"maxErrors":10,"maxTotalErrors":3,"expSrcs":["https://secure.aadcdn.microsoftonline-p.com/ests/","https://login.microsoftonline.com",".login.microsoftonline.com"],"envErrorRedirect":true,"envErrorUrl":"/common/handlers/enverror"},"loader":{"cdnRoots":[]},"serverDetails":{"slc":"ProXXXXes","dc":"DUB2","ri":"ESTXXXX_74","ver":{"v":[2,1,7758,23]},"rt":"2018-06-14T07:59:37","et":1},"fBreakBrandingSigninString":true};
//]]></script>
<script type="text/javascript">//<![CDATA[
!function(){var e=window,r=e.$Debug=e.$Debug||{},n=e.$Config||{};if(!r.appendLog){var t=[],o=0;r.appendLog=function(e){var r=n.maxDebugLog||25,a=(new Date).toUTCString()+":"+e;t.push(o+":"+a),t.length>r&&t.shift(),o++},r.getLogs=function(){return t}}}(),function(){function e(e,r){function n(a){var i=e[a];return t-1>a?void(o.r[i]?n(a+1):o.when(i,function(){n(a+1)})):void r(i)}var t=e.length;n(0)}function r(e,r,a){function i(){var e=!!s.method,o=e?s.method:a[0],i=s.extraArgs||[],u=t.$WebWatson;try{var c=n(a,!e);if(i&&i.length>0)for(var l=i.length,d=0;l>d;d++)c.push(i[d]);o.apply(r,c)}catch(f){return void(u&&u.submitFromException&&u.submitFromException(f))}}var s=o.r&&o.r[e];return r=r?r:this,s&&(s.skipTimeout?i():t.setTimeout(i,0)),s}function n(e,r){return Array.prototype.slice.call(e,r?1:0)}var t=window;t.$Do||(t.$Do={q:[],r:[],removeItems:[],lock:0,o:[]});var o=t.$Do;o.when=function(n,t){function a(e){r(e,i,s)||o.q.push({id:e,c:i,a:s})}var i=0,s=[],u=1,c="function"==typeof t;c||(i=t,u=2);for(var l=u;l<arguments.length;l++)s.push(arguments[l]);n instanceof Array?e(n,a):a(n)},o.register=function(e,n,t){if(!o.r[e]){o.o.push(e);var a={};if(n&&(a.method=n),t&&(a.skipTimeout=t),arguments&&arguments.length>3){a.extraArgs=[];for(var i=3;i<arguments.length;i++)a.extraArgs.push(arguments[i])}o.r[e]=a,o.lock++;try{for(var s=0;s<o.q.length;s++){var u=o.q[s];u.id==e&&r(e,u.c,u.a)&&o.removeItems.push(u)}}catch(c){throw c}finally{if(o.lock--,0===o.lock){for(var l=0;l<o.removeItems.length;l++)for(var d=o.removeItems[l],f=0;f<o.q.length;f++)if(o.q[f]===d){o.q.splice(f,1);break}o.removeItems=[]}}}},o.unregister=function(e){o.r[e]&&delete o.r[e]}}(),function(){function e(e,r){var n=c.$Debug;n&&n.appendLog&&(r&&(e+=" '"+(r.src||r.href||"")+"'",e+=", id:"+(r.id||""),e+=", async:"+(r.async||""),e+=", defer:"+(r.defer||"")),n.appendLog(e))}function r(){var e=c.$Config||{},r=e.loader||{};return r.slReportFailure||e.slReportFailure||!1}function n(){var e=c.$Config||{},r=e.loader||{};return r.redirectToErrorPageOnLoadFailure||!1}function t(e){var r=e.indexOf("?"),n=r>-1?r:e.length;return n>f&&e.substr(n-f,f).toLowerCase()===d}function o(e,r,n){var o=t(e)?a(e):i(e);return r&&(o.id=r),"function"==typeof o.setAttribute&&(o.setAttribute("crossorigin","anonymous"),n&&"string"==typeof n&&o.setAttribute("integrity",n)),o}function a(e){var r=l.createElement("link");return r.rel="stylesheet",r.type="text/css",r.href=e,r}function i(e){var r=l.createElement("script");return r.type="text/javascript",r.src=e,r.defer=!1,r.async=!1,r}function s(e){var r=!0,n=e.src||e.href||"";if(n){if(t(n))try{e.sheet&&e.sheet.cssRules&&!e.sheet.cssRules.length&&(r=!1)}catch(o){}}else r=!1;return r}function u(){function r(e){if(!(u&&u.length>1))return e;for(var r=0;r<u.length;r++)if(e.startsWith(u[r]))return u[r+1<u.length?r+1:0]+e.substring(u[r].length);return e}function n(t,i,u){if(t<f.length){var c=f[t];if(!c||!c.srcPath)return void n(t+1,i,u);c.retry>0&&(c.srcPath=r(c.srcPath),c.origId||(c.origId=c.id),c.id=c.origId+"_Retry_"+c.retry);var g=o(c.srcPath,c.id,c.integrity),h=function(){return e("[$Loader]: "+(d.failMessage||"Failed"),g),c.retry<a?(c.retry++,void n(t,i,u)):void(u&&u())},v=function(){s(g)?(e("[$Loader]: "+(d.successMessage||"Loaded"),g),n(t+1,i,u)):h()};g.onload=v,g.onerror=h,g.onreadystatechange=function(){"loaded"===g.readyState?setTimeout(v,500):"complete"===g.readyState&&v()};var p=l.getElementsByTagName("head")[0];p.appendChild(g),e("[$Loader]: Loading '"+(c.srcPath||"")+"', id:"+(c.id||""))}else i&&i()}var t=c.$Config||{},a=t.slMaxRetry||2,i=t.loader||{},u=i.cdnRoots||[],d=this,f=[];d.retryOnError=!0,d.successMessage="Loaded",d.failMessage="Error",d.Add=function(e,r,n,t){e&&f.push({srcPath:e,id:r,retry:t||0,integrity:n})},d.AddLoaded=function(){},d.AddForReload=function(e){var r=e.src||e.href||"";d.Add(r,"AddForReload",e.integrity,1)},d.AddIf=function(e,r,n){e&&d.Add(r,n)},d.Load=function(e,r){n(0,e,r)}}var c=window,l=c.document,d=".css",f=d.length;u.On=function(e,r){if(!e)throw"The target element must be provided and cannot be null.";r?u.OnError(e):u.OnSuccess(e)},u.OnSuccess=function(t,o,a){var i=t.src||t.href||"",c=r(),l=n();if(!t)throw"The target element must be provided and cannot be null.";if(s(t)){e("[$Loader]: Loaded",t);var d=new u;d.failMessage="Reload Failed",d.successMessage="Reload Success",d.AddLoaded(t,o,a),d.Load(null,function(){if(c)throw"Unexpected state. resourceLoader.Load() failed despite initial load success. ['"+i+"']";l&&(document.location.href="/error.aspx?err=504")})}else u.OnError(t,o,a)},u.OnError=function(t,o,a){var i=t.src||t.href||"",s=r(),c=n();if(!t)throw"The target element must be provided and cannot be null.";e("[$Loader]: Failed",t);var l=new u;l.failMessage="Reload Failed",l.successMessage="Reload Success",l.AddForReload(t,o,a),l.Load(null,function(){if(s)throw"Failed to load external resource ['"+i+"']";c&&(document.location.href="/error.aspx?err=504")})},c.$Loader=u}(),function(){function e(){if(!$){var e=new v.$Loader;e.AddIf(!v.jQuery,y.sbundle,"WebWatson_DemandSupport"),y.sbundle=null,delete y.sbundle,e.AddIf(!v.$Api,y.fbundle,"WebWatson_DemandFramework"),y.fbundle=null,delete y.fbundle,e.Add(y.bundle,"WebWatson_DemandLoaded"),e.Load(r,n),$=!0}}function r(){if(v.$WebWatson){if(v.$WebWatson.isProxy)return void n();m.when("$WebWatson.full",function(){for(;b.length>0;){var e=b.shift();e&&v.$WebWatson[e.cmdName].apply(v.$WebWatson,e.args)}})}}function n(){var e=v.$WebWatson?v.$WebWatson.isProxy:!0;if(e){if(!w&&JSON){try{var r=new XMLHttpRequest;r.open("POST",y.url),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json; charset=UTF-8"),r.setRequestHeader("canary",p.apiCanary),r.setRequestHeader("client-request-id",p.correlationId),r.setRequestHeader("hpgid",p.hpgid||0),r.setRequestHeader("hpgact",p.hpgact||0);for(var n=-1,o=0;o<b.length;o++)if("submit"===b[o].cmdName){n=o;break}var a=b[n]?b[n].args||[]:[],i={sr:y.sr,ec:"Failed to load external resource [Core Watson files]",wec:55,idx:1,pn:p.pgid||"",sc:p.scid||0,hpg:p.hpgid||0,msg:"Failed to load external resource [Core Watson files]",url:a[1]||"",ln:0,ad:0,an:!1,cs:"",sd:p.serverDetails,ls:null,diag:h(y)};r.send(JSON.stringify(i))}catch(s){}w=!0}y.loadErrorUrl&&window.location.assign(y.loadErrorUrl)}t()}function t(){b=[],v.$WebWatson=null}function o(r){return function(){var n=arguments;b.push({cmdName:r,args:n}),e()}}function a(){var e=["foundException","resetException","submit"],r=this;r.isProxy=!0;for(var n=e.length,t=0;n>t;t++){var a=e[t];a&&(r[a]=o(a))}}function i(e,r,n,t,o,a,i){var s=v.event;a||(a=d(o||s,i?i+2:2)),v.$Debug&&v.$Debug.appendLog&&v.$Debug.appendLog("[WebWatson]:"+(e||"")+" in "+(r||"")+" @ "+(n||"??")),W.submit(e,r,n,t,o||s,a,i)}function s(e,r){return{signature:e,args:r,toString:function(){return this.signature}}}function u(e){for(var r=[],n=e.split("\n"),t=0;t<n.length;t++)r.push(s(n[t],[]));return r}function c(e){for(var r=[],n=e.split("\n"),t=0;t<n.length;t++){var o=s(n[t],[]);n[t+1]&&(o.signature+="@"+n[t+1],t++),r.push(o)}return r}function l(e){if(!e)return null;try{if(e.stack)return u(e.stack);if(e.error){if(e.error.stack)return u(e.error.stack)}else if(window.opera&&e.message)return c(e.message)}catch(r){}return null}function d(e,r){var n=[];try{for(var t=arguments.callee;r>0;)t=t?t.caller:t,r--;for(var o=0;t&&L>o;){var a="InvalidMethod()";try{a=t.toString()}catch(i){}var u=[],c=t.args||t.arguments;if(c)for(var d=0;d<c.length;d++)u[d]=c[d];n.push(s(a,u)),t=t.caller,o++}}catch(i){n.push(s(i.toString(),[]))}var f=l(e);return f&&(n.push(s("--- Error Event Stack -----------------",[])),n=n.concat(f)),n}function f(e){if(e)try{var r=/function (.{1,})\(/,n=r.exec(e.constructor.toString());return n&&n.length>1?n[1]:""}catch(t){}return""}function g(e){if(e)try{if("string"!=typeof e&&JSON&&JSON.stringify){var r=f(e),n=JSON.stringify(e);return n&&"{}"!==n||(e.error&&(e=e.error,r=f(e)),n=JSON.stringify(e),n&&"{}"!==n||(n=e.toString())),r+":"+n}}catch(t){}return""+(e||"")}function h(e){var r=[];try{if(jQuery?(r.push("jQuery v:"+jQuery().jquery),r.push(jQuery.easing?"jQuery.easing:"+JSON.stringify(jQuery.easing):"jQuery.easing is not defined")):r.push("jQuery is not defined"),e&&e.expectedVersion&&r.push("Expected jQuery v:"+e.expectedVersion),m){var n,t="";for(n=0;n<m.o.length;n++)t+=m.o[n]+";";for(r.push("$Do.o["+t+"]"),t="",n=0;n<m.q.length;n++)t+=m.q[n].id+";";r.push("$Do.q["+t+"]")}if(v.$Debug&&v.$Debug.getLogs){var o=v.$Debug.getLogs();o&&o.length>0&&(r=r.concat(o))}if(b)for(var a=0;a<b.length;a++){var i=b[a];if(i&&"submit"===i.cmdName)try{if(JSON&&JSON.stringify){var s=JSON.stringify(i);s&&r.push(s)}}catch(u){r.push(g(u))}}}catch(c){r.push(g(c))}return r}var v=window,p=v.$Config||{},y=p.watson,m=v.$Do;if(!v.$WebWatson&&y){var b=[],$=!1,w=!1,L=10,W=v.$WebWatson=new a;W.CB={},W._orgErrorHandler=v.onerror,v.onerror=i,W.errorHooked=!0,m.when("jQuery.version",function(e){y.expectedVersion=e}),m.register("$WebWatson")}}(),function(){function e(e,r){for(var n=r.split("."),t=n.length,o=0;t>o&&null!==e&&void 0!==e;)e=e[n[o++]];return e}function r(r){var n=null;return null===u&&(u=e(a,"Constants")),null!==u&&r&&(n=e(u,r)),null===n||void 0===n?"":n.toString()}function n(n){var t=null;return null===i&&(i=e(a,"$Config.strings")),null!==i&&n&&(t=e(i,n.toLowerCase())),(null===t||void 0===t)&&(t=r(n)),null===t||void 0===t?"":t.toString()}function t(e,r){var t=null;return e&&r&&r[e]&&(t=n("errors."+r[e])),t||(t=n("errors."+e)),t||(t=n("errors."+c)),t||(t=n(c)),t}function o(n){var t=null;return null===s&&(s=e(a,"$Config.urls")),null!==s&&n&&(t=e(s,n.toLowerCase())),(null===t||void 0===t)&&(t=r(n)),null===t||void 0===t?"":t.toString()}var a=window,i=null,s=null,u=null,c="GENERIC_ERROR";a.GetString=n,a.GetErrorString=t,a.GetUrl=o}(),function(){var e=window,r=e.$Config||{};e.$B=r.browser||{}}();
//]]></script>
<script type="text/javascript">
ServerData = $Config;
</script>
<link crossorigin="anonymous" href="https://secure.aadcdn.microsoftonline-p.com/ests/2.1.7758.23/content/cdnbundles/converged.login.min.css" rel="stylesheet" onerror='$Loader.On(this,true)' onload='$Loader.On(this)' integrity='sha384-xznjl5MWBmtr74oDcjcoEsoDik1lgcOweUsrT60BfsR6jwKU+GUeTndhop6vsuIN' />
<script crossorigin="anonymous" src="https://secure.aadcdn.microsoftonline-p.com/ests/2.1.7758.23/content/cdnbundles/convergederror_core.min.js" onerror='$Loader.On(this,true)' onload='$Loader.On(this)' integrity='sha384-lgSDRKhIffvDT8BSmPSbneJVdrOu/tKUmh6uRbf9nuR1xDv76fe4i3KXJ+75ScIo'></script>
<script crossorigin="anonymous" src="https://secure.aadcdn.microsoftonline-p.com/ests/2.1.7758.23/content/cdnbundles/convergederrorstrings-en.min.js" onerror='$Loader.On(this,true)' onload='$Loader.On(this)' integrity='sha384-evfKROubLaYI40lsZRH/IKXjyZqDQI1y4ncuHg5TxmwYJHozqVZFllXPipP0jZ1k'></script>
</head>
<body data-bind="defineGlobals: ServerData, bodyCssClass" class="cb" style="display: none">
<script type="text/javascript">//<![CDATA[
!function(){var e=window,o=e.document,i=e.$Config||{};if(e.self===e.top)o&&o.body&&(o.body.style.display="block");else if(!i.allowFrame){var s=e.self.location.href,l=s.indexOf("#"),n=-1!==l,t=s.indexOf("?"),f=n?l:s.length,d=-1===t||n&&t>l?"?":"&";s=s.substr(0,f)+d+"iframe-request-id="+i.sessionId+s.substr(f),e.top.location=s}}();
//]]></script>
</body>
</html>
Which appears to be another log in page.
Any Help would be appreciated.