How to make source code from CQDPowerShell cmdlet acquiring access token non-interactively

%3CLINGO-SUB%20id%3D%22lingo-sub-1325146%22%20slang%3D%22en-US%22%3EHow%20to%20make%20source%20code%20from%20CQDPowerShell%20cmdlet%20acquiring%20access%20token%20non-interactively%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1325146%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20are%20trying%20to%20implement%20similar%20to%20code%20taken%20from%26nbsp%3BCQDPowerShell%20and%20re-written%20in%20C%23%20in%20our%20.Net%20application.%20But%20we%20do%20not%20find%20a%20way%20how%20to%20make%20non-interactive%20access%2Frefresh%20token%20acquisition%20instead%20of%20interactive%20access%20token%20acquisition%20with%20popup%20window%20with%20entering%20credentials%20.%20We%20find%20only%20how%20to%20get%20access%20token%20in%20the%20PowerShell%20cmdlet%26nbsp%3BCQDPowerShell%20and%20the%20access%20token%20lives%20only%201%20hour.%20Then%20the%20access%20token%20have%20to%20acquired%20interactively%20again.%26nbsp%3B%20While%20we%20need%20to%20have%20the%20code%20running%20indefinitely%20without%20the%20user%20interaction.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3Estring%26nbsp%3BredirectUrl%26nbsp%3B%3D%26nbsp%3BSystem.Web.HttpUtility.UrlEncode(%22https%3A%2F%2Fcqd.teams.microsoft.com%2Fspd%2F%22)%3B%0Astring%26nbsp%3BresourceUrl%26nbsp%3B%3D%26nbsp%3BSystem.Web.HttpUtility.UrlEncode(%22https%3A%2F%2Fcqd.teams.microsoft.com%22)%3B%0Astring%26nbsp%3BclientId%26nbsp%3B%3D%26nbsp%3B%22c61d67cf-295a-462c-972f-33af37008751%22%3B%0A%20%0Astring%26nbsp%3Burl%26nbsp%3B%3D%26nbsp%3B%24%22https%3A%2F%2Flogin.microsoftonline.com%2Fcommon%2Foauth2%2Fauthorize%3Fresponse_type%3Dtoken%26amp%3Bredirect_uri%3D%7BredirectUrl%7D%26amp%3Bclient_id%3D%7BclientId%7D%22%26nbsp%3B%2B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%24%22%26amp%3Bprompt%3Dlogin%26amp%3Bnonce%3D%24nonce%26amp%3Bresource%3D%7BresourceUrl%7D%22%3B%0A%20%0AForm%26nbsp%3Bform%26nbsp%3B%3D%26nbsp%3Bnew%26nbsp%3BForm%26nbsp%3B%7B%26nbsp%3BWidth%26nbsp%3B%3D%26nbsp%3B440%2C%26nbsp%3BHeight%26nbsp%3B%3D%26nbsp%3B640%26nbsp%3B%7D%3B%0AWebBrowser%26nbsp%3Bweb%26nbsp%3B%3D%26nbsp%3Bnew%26nbsp%3BWebBrowser%26nbsp%3B%7B%26nbsp%3BWidth%26nbsp%3B%3D%26nbsp%3B420%2C%26nbsp%3BHeight%26nbsp%3B%3D%26nbsp%3B600%2C%26nbsp%3BUrl%26nbsp%3B%3D%26nbsp%3Bnew%26nbsp%3BUri(url)%26nbsp%3B%7D%3B%0A%20%0Aweb.DocumentCompleted%26nbsp%3B%2B%3D%26nbsp%3B(sender%2C%26nbsp%3Be)%26nbsp%3B%3D%26gt%3B%0A%7B%0A%20%20%20%20%20%20string%26nbsp%3Buri%26nbsp%3B%3D%26nbsp%3Bweb.Url.AbsoluteUri%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bif%26nbsp%3B(Regex.Match(uri%2C%26nbsp%3B%22error%3D%5B%5E%26amp%3B%5D*%7Caccess_token%3D%5B%5E%26amp%3B%5D*%7Ccode%3D%5B%5E%26amp%3B%5D*%22).Success)%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%7B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bform.Close()%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%7D%0A%7D%3B%0A%20%0Aweb.ScriptErrorsSuppressed%26nbsp%3B%3D%26nbsp%3Btrue%3B%0Aform.Controls.Add(web)%3B%0Aform.Shown%26nbsp%3B%2B%3D%26nbsp%3B(sender%2C%26nbsp%3Be)%26nbsp%3B%3D%26gt%3B%0A%7B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bform.Activate()%3B%0A%7D%3B%0A%20%0Aform.ShowDialog()%3B%0A%20%0Astring%26nbsp%3BresponseUrl%26nbsp%3B%3D%26nbsp%3Bweb.Url.ToString()%3B%0A%20%0Aint%26nbsp%3BcodeStartIndex%26nbsp%3B%3D%26nbsp%3BresponseUrl.IndexOf(%22access_token%3D%22)%26nbsp%3B%2B%26nbsp%3B%22access_token%3D%22.Length%3B%0Aint%26nbsp%3BcodeEndIndex%26nbsp%3B%3D%26nbsp%3BresponseUrl.IndexOf(%22%26amp%3B%22)%3B%0Astring%26nbsp%3Bcode%26nbsp%3B%3D%26nbsp%3BresponseUrl.Substring(codeStartIndex%2C%26nbsp%3BcodeEndIndex%26nbsp%3B-%26nbsp%3BcodeStartIndex)%3B%3C%2FPRE%3E%3CP%3EThe%20code%20above%20retrieves%20access%20code%2C%20as%20well%20as%20possible%20to%20retrieve%20%22access%20code%22%2C%20by%20replacing%20%22response_type%3Dtoken%22%20into%20%22response_type%3Dcode%22.%20But%20do%20not%20know%20how%20to%20use%20that%20%22access%20code%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20need%20this%20API%20to%20retrieve%20Teams%20Call%20Quality%20Dashboard%20statistics.%20Maybe%20there%20are%20other%20APIs%20to%20retrieve%20Teams%20Call%20Quality%20statistics%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1325146%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20Teams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1335212%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20make%20source%20code%20from%20CQDPowerShell%20cmdlet%20acquiring%20access%20token%20non-interactively%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1335212%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F631014%22%20target%3D%22_blank%22%3E%40Oleksii_Kolinko%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20find%20the%20code%20here%20in%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fv-karapa%2FTeamsPolicyaAsignment-Bulk%2Fblob%2Fmaster%2FPolicyPackageAssignment.ps1%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Egitrepo.%26nbsp%3B%3C%2FA%3E%3C%2FP%3E%0A%3CP%3Ehere%20we%20used%20loop%20the%20access%20code%20to%20generate%20each%20time%20for%20the%20requirement.%3C%2FP%3E%0A%3CP%3EToken1%2C%20Token2%2C%20Token3%20will%20generate%20in%20each%20request.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20find%20the%20code%20for%20getting%20%3CA%20href%3D%22https%3A%2F%2Ftotietoot.nl%2Ftech%2Fpowershell-function-to-retrieve-oauth-access-token%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3ERefresh%20token%3C%2FA%3E.%20Use%20this%20function%20to%20call%20each%20time%20to%20retrieve%20or%20get%20the%20access%20token.%3C%2FP%3E%0A%3CP%3EPlease%20check%20above%20solutions%20and%20let%20us%20know%20if%20you%20need%20any%20thing.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1335453%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20make%20source%20code%20from%20CQDPowerShell%20cmdlet%20acquiring%20access%20token%20non-interactively%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1335453%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F635527%22%20target%3D%22_blank%22%3E%40teams1535%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFirst%20example%20works%20with%20client%20secret%2C%20which%20in%20this%20case%20is%20not%20availible.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhile%20according%20to%20seconds%20example%20I%20written%20the%20code%2C%20which%20should%20theoretically%20return%20access%20token%20out%20of%20%22authorization%20code%22%3A%3C%2FP%3E%3CPRE%3E%3CSPAN%3Eusing%3C%2FSPAN%3E%26nbsp%3B(%3CSPAN%3EHttpClient%3C%2FSPAN%3E%26nbsp%3BhttpClient%26nbsp%3B%3CSPAN%3E%3D%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%3Enew%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%3EHttpClient%3C%2FSPAN%3E())%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%7B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%3Estring%3C%2FSPAN%3E%26nbsp%3BnewRequestPath%26nbsp%3B%3CSPAN%3E%3D%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%3E%24%22https%3A%2F%2Flogin.microsoftonline.com%2F%3CTENANT%20guid%3D%22%22%3E%2Foauth2%2Fv2.0%2Ftoken%22%3C%2FTENANT%3E%3C%2FSPAN%3E%3B%0A%20%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%3Estring%3C%2FSPAN%3E%26nbsp%3BrequestBOdy%26nbsp%3B%3CSPAN%3E%3D%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%3E%24%22grant_type%3Dauthorization_code%26amp%3Bclient_id%3D%3C%2FSPAN%3E%7BclientId%7D%3CSPAN%3E%26amp%3Bredirect_uri%3D%3C%2FSPAN%3E%7BredirectUrl%7D%3CSPAN%3E%26amp%3Bcode%3D%3C%2FSPAN%3E%7Bcode%7D%3CSPAN%3E%22%3C%2FSPAN%3E%3B%0A%20%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%3EHttpContent%3C%2FSPAN%3E%26nbsp%3BhttpContent%26nbsp%3B%3CSPAN%3E%3D%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%3Enew%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%3EStringContent%3C%2FSPAN%3E(requestBOdy%2C%26nbsp%3B%3CSPAN%3EEncoding%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3EUTF8%2C%26nbsp%3B%3CSPAN%3E%22application%2Fx-www-form-urlencoded%22%3C%2FSPAN%3E)%3B%0A%20%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%3EHttpRequestMessage%3C%2FSPAN%3E%26nbsp%3Brequest%26nbsp%3B%3CSPAN%3E%3D%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%3Enew%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%3EHttpRequestMessage%3C%2FSPAN%3E(%3CSPAN%3EHttpMethod%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3EPost%2C%26nbsp%3BnewRequestPath)%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Brequest%3CSPAN%3E.%3C%2FSPAN%3EContent%26nbsp%3B%3CSPAN%3E%3D%3C%2FSPAN%3E%26nbsp%3BhttpContent%3B%0A%20%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%3ETask%3C%2FSPAN%3E%26lt%3B%3CSPAN%3EHttpResponseMessage%3C%2FSPAN%3E%26gt%3B%26nbsp%3Bresponse%26nbsp%3B%3CSPAN%3E%3D%3C%2FSPAN%3E%26nbsp%3BhttpClient%3CSPAN%3E.%3C%2FSPAN%3ESendAsync(request)%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bresponse%3CSPAN%3E.%3C%2FSPAN%3EWait()%3B%0A%20%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%3ETask%3C%2FSPAN%3E%26lt%3B%3CSPAN%3Estring%3C%2FSPAN%3E%26gt%3B%26nbsp%3BresponseString%26nbsp%3B%3CSPAN%3E%3D%3C%2FSPAN%3E%26nbsp%3Bresponse%3CSPAN%3E.%3C%2FSPAN%3EResult%3CSPAN%3E.%3C%2FSPAN%3EContent%3CSPAN%3E.%3C%2FSPAN%3EReadAsStringAsync()%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BresponseString%3CSPAN%3E.%3C%2FSPAN%3EWait()%3B%0A%20%0A%20%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%7D%3C%2FPRE%3E%3CP%3E%26nbsp%3BBut%20it%20returns%20the%20following%20error%20message%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%22%7B%5C%22error%5C%22%3A%5C%22invalid_client%5C%22%2C%5C%22error_description%5C%22%3A%5C%22AADSTS7000218%3A%20The%20request%20body%20must%20contain%20the%20following%20parameter%3A%20'client_assertion'%20or%20'client_secret'.%5C%5Cr%5C%5CnTrace%20ID%3A%20d89e74e1-36dd-4807-9c51-dda7003c0700%5C%5Cr%5C%5CnCorrelation%20ID%3A%20eb4c20b0-7ab5-41c4-a7b3-3d793e6de0b6%5C%5Cr%5C%5CnTimestamp%3A%202020-04-24%2012%3A07%3A16Z%5C%22%2C%5C%22error_codes%5C%22%3A%5B7000218%5D%2C%5C%22timestamp%5C%22%3A%5C%222020-04-24%2012%3A07%3A16Z%5C%22%2C%5C%22trace_id%5C%22%3A%5C%22d89e74e1-36dd-4807-9c51-dda7003c0700%5C%22%2C%5C%22correlation_id%5C%22%3A%5C%22eb4c20b0-7ab5-41c4-a7b3-3d793e6de0b6%5C%22%2C%5C%22error_uri%5C%22%3A%5C%22%3CA%20href%3D%22https%3A%2F%2Flogin.microsoftonline.com%2Ferror%3Fcode%3D7000218%5C%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Flogin.microsoftonline.com%2Ferror%3Fcode%3D7000218%5C%3C%2FA%3E%22%7D%22%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1357734%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20make%20source%20code%20from%20CQDPowerShell%20cmdlet%20acquiring%20access%20token%20non-interactively%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1357734%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20contacted%20the%20owner%20of%20the%20PowerShell%20cmdlet%2C%20he%20told%20me%20that%20there%20is%20no%20non-interactive%20way%20of%20getting%20the%20access%20token.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1999666%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20make%20source%20code%20from%20CQDPowerShell%20cmdlet%20acquiring%20access%20token%20non-interactively%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1999666%22%20slang%3D%22en-US%22%3E%3CP%3Ehi%20there%20%3A)%3C%2Fimg%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F631014%22%20target%3D%22_blank%22%3E%40Oleksii_Kolinko%3C%2FA%3E%26nbsp%3Bjust%20wondering%20if%20you%20have%20found%20a%20way%20to%20do%20non-interactive%20login%20on%20the%26nbsp%3B%3CSPAN%3ECQDPowerShell%20module.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Ethanks%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EEd%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2043446%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20make%20source%20code%20from%20CQDPowerShell%20cmdlet%20acquiring%20access%20token%20non-interactively%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2043446%22%20slang%3D%22en-US%22%3E%3CP%3EI%20did%20not%20found%20the%20way.%20It%20does%20not%20exist.%20I%20got%20a%20response%20from%20a%20developer%20of%20the%20module.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2200777%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20make%20source%20code%20from%20CQDPowerShell%20cmdlet%20acquiring%20access%20token%20non-interactively%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2200777%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F631014%22%20target%3D%22_blank%22%3E%40Oleksii_Kolinko%3C%2FA%3E.%20Do%20you%20know%20if%20there%C2%B4s%20a%20way%20to%20request%20to%20the%20developers%20of%20the%20CQD%20to%20e%3CSPAN%3Enable%20the%20option%20%22Allow%20public%20client%20flows%22%20for%20the%20Microsoft%20Application%3A%20Call%20Quality%20Dashboard%2C%20Client%20Id%3A%20c61d67cf-295a-462c-972f-33af37008751%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ECurrently%2C%20a%20similar%20request%20exists%20in%20Teams%20User%20Voice%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fmicrosoftteams.uservoice.com%2Fforums%2F555103-public%2Fsuggestions%2F40344751-make-api-for-teams-call-quality-dashboard-availibl%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmicrosoftteams.uservoice.com%2Fforums%2F555103-public%2Fsuggestions%2F40344751-make-api-for-teams-call-quality-dashboard-availibl%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EThanks.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

We are trying to implement similar to code taken from CQDPowerShell and re-written in C# in our .Net application. But we do not find a way how to make non-interactive access/refresh token acquisition instead of interactive access token acquisition with popup window with entering credentials . We find only how to get access token in the PowerShell cmdlet CQDPowerShell and the access token lives only 1 hour. Then the access token have to acquired interactively again.  While we need to have the code running indefinitely without the user interaction.

 

string redirectUrl = System.Web.HttpUtility.UrlEncode("https://cqd.teams.microsoft.com/spd/");
string resourceUrl = System.Web.HttpUtility.UrlEncode("https://cqd.teams.microsoft.com");
string clientId = "c61d67cf-295a-462c-972f-33af37008751";
 
string url = $"https://login.microsoftonline.com/common/oauth2/authorize?response_type=token&redirect_uri={redirectUrl}&client_id={clientId}" +
                $"&prompt=login&nonce=$nonce&resource={resourceUrl}";
 
Form form = new Form { Width = 440, Height = 640 };
WebBrowser web = new WebBrowser { Width = 420, Height = 600, Url = new Uri(url) };
 
web.DocumentCompleted += (sender, e) =>
{
      string uri = web.Url.AbsoluteUri;
      if (Regex.Match(uri, "error=[^&]*|access_token=[^&]*|code=[^&]*").Success)
      {
                    form.Close();
      }
};
 
web.ScriptErrorsSuppressed = true;
form.Controls.Add(web);
form.Shown += (sender, e) =>
{
       form.Activate();
};
 
form.ShowDialog();
 
string responseUrl = web.Url.ToString();
 
int codeStartIndex = responseUrl.IndexOf("access_token=") + "access_token=".Length;
int codeEndIndex = responseUrl.IndexOf("&");
string code = responseUrl.Substring(codeStartIndex, codeEndIndex - codeStartIndex);

The code above retrieves access code, as well as possible to retrieve "access code", by replacing "response_type=token" into "response_type=code". But do not know how to use that "access code".

 

We need this API to retrieve Teams Call Quality Dashboard statistics. Maybe there are other APIs to retrieve Teams Call Quality statistics?

7 Replies

@Oleksii_Kolinko 

Please find the code here in gitrepo. 

here we used loop the access code to generate each time for the requirement.

Token1, Token2, Token3 will generate in each request.

 

Please find the code for getting Refresh token. Use this function to call each time to retrieve or get the access token.

Please check above solutions and let us know if you need any thing.

@teams1535 

 

First example works with client secret, which in this case is not availible.

 

While according to seconds example I written the code, which should theoretically return access token out of "authorization code":

using (HttpClient httpClient = new HttpClient())
            {
                string newRequestPath = $"https://login.microsoftonline.com/<tenant guid>/oauth2/v2.0/token";
 
                string requestBOdy = $"grant_type=authorization_code&client_id={clientId}&redirect_uri={redirectUrl}&code={code}";
 
                HttpContent httpContent = new StringContent(requestBOdy, Encoding.UTF8, "application/x-www-form-urlencoded");
 
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, newRequestPath);
                request.Content = httpContent;
 
                Task<HttpResponseMessage> response = httpClient.SendAsync(request);
                response.Wait();
 
                Task<string> responseString = response.Result.Content.ReadAsStringAsync();
                responseString.Wait();
 
 
            }

 But it returns the following error message:

 

"{\"error\":\"invalid_client\",\"error_description\":\"AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.\\r\\nTrace ID: d89e74e1-36dd-4807-9c51-dda7003c0700\\r\\nCorrelation ID: eb4c20b0-7ab5-41c4-a7b3-3d793e6de0b6\\r\\nTimestamp: 2020-04-24 12:07:16Z\",\"error_codes\":[7000218],\"timestamp\":\"2020-04-24 12:07:16Z\",\"trace_id\":\"d89e74e1-36dd-4807-9c51-dda7003c0700\",\"correlation_id\":\"eb4c20b0-7ab5-41c4-a7b3-3d793e6de0b6\",\"error_uri\":\"https://login.microsoftonline.com/error?code=7000218\"}"

I have contacted the owner of the PowerShell cmdlet, he told me that there is no non-interactive way of getting the access token.

hi there :)

@Oleksii_Kolinko just wondering if you have found a way to do non-interactive login on the CQDPowerShell module.

 

thanks,

Ed

I did not found the way. It does not exist. I got a response from a developer of the module.

Hi @Oleksii_Kolinko. Do you know if there´s a way to request to the developers of the CQD to enable the option "Allow public client flows" for the Microsoft Application: Call Quality Dashboard, Client Id: c61d67cf-295a-462c-972f-33af37008751?

For the moment, I already voted to your request in Teams User Voice:

https://microsoftteams.uservoice.com/forums/555103-public/suggestions/40344751-make-api-for-teams-ca...

Thanks.

@jonvasbar 

I tried passing credentials to Invoke-WebRequest (Similar issue to https://docs.microsoft.com/en-us/answers/questions/290269/invoke-webrequest-to-get-access-token-for-...), but this did not get the token (in $response.content). What else do I need to add to this code to get the token?

 

$AdminName = "r987327"
$Pass = Get-Content "encrypted_pass.txt" | ConvertTo-SecureString
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Pass
$configRest = Invoke-RestMethod -Uri "https://cqd.teams.microsoft.com/repository/clientconfiguration" -Method Get -SessionVariable WebSession -UserAgent "CQDPowerShell V2.0"
$WebResource = $configRest.AuthLoginResource
$client_id = $configRest.AuthWebAppClientId
Add-Type -AssemblyName System.Web
$resourceUrl = $WebResource
$redirectUrl = "https://cqd.teams.microsoft.com/spd/"
$nonce = [guid]::NewGuid().GUID
$url = "https://login.microsoftonline.com/common/oauth2/authorize?response_type=token&redirect_uri=" + [System.Web.HttpUtility]::UrlEncode($redirectUrl) + "&client_id=$client_id" + "&prompt=login" + "&nonce=$nonce" + "&resource=" + [System.Web.HttpUtility]::UrlEncode($WebResource)
$response = Invoke-WebRequest -Uri $url -Method GET -Headers @{Metadata="true"}  -Credential $cred