Nov 13 2022 11:23 PM - edited Nov 14 2022 01:19 AM
Hello all,
I've been trying to get a MS Teams Custom App running with SSO for several days now. All the examples I have looked at work but do not apply to my application. Maybe I have a wrong approach.
I have a web page (CSHTML) that is populated with data on view data from the associated controller. This web page needs to request and process data from MS-Graph (delegated) in the controller. For this I use from the repository https://github.com/officedev/microsoft-teams-samples.git the sample `/samples/tab-sso/csharp/TeamsTabSSO`.
My problem is, that the controller code of the web page, for the view data was already called before the 'accessToken" from the javascript part of the web page was delivered to the controller.
Code example of the controllers;
-------------------------------------------------------
public IActionResult Index()
{
ViewBag.clientId = _configuration["AzureAd:ClientId"].ToString();
ViewBag.applicationIdURI = _configuration["AzureAd:ApplicationIdURI"].ToString();
here I want to access MS-graph via the accessToken e.g:
var me = await MSGraphClient.GetMeAsync(accessToken).ConfigureAwait(false);
var groups = await MSGraphClient.GetMeMemberOfAsync(accessToken).ConfigureAwait(false);
return View();}
-------------------------------------------------------
but only after running the controller code of the web page I get the call of the controller method 'GetUserAccessToken' in which the accessToken is delivered.
-------------------------------------------------------
[Authorize]
[HttpGet("GetUserAccessToken")]
public async Task<ActionResult<string>> GetUserAccessToken()
{
try
{
return await SSOAuthHelper.GetAccessTokenOnBehalfUserAsync(_configuration, _httpClientFactory, _httpContextAccessor);
}
catch (Exception)
{
return null;
}
}
I would appreciate your help. Maybe there is even an example which applies to me.
Thanks
Mike
Nov 14 2022 01:48 AM
@Mikel85570 - Could you please refer this document?
Code configuration for enabling SSO for tabs - Teams | Microsoft Learn
Nov 14 2022 02:16 AM
Nov 20 2022 10:34 PM - edited Nov 21 2022 02:12 AM
SolutionIf you want to get id token at server side before page is loaded, it's not possible. You will get that at client side only.
Thanks,
Prasad Das
----------------------------------------------------------------
If the response is helpful, please click "**Mark as Best Response**" and like it. You can share your feedback via Microsoft Teams Developer Feedback link.
Nov 20 2022 10:34 PM - edited Nov 21 2022 02:12 AM
SolutionIf you want to get id token at server side before page is loaded, it's not possible. You will get that at client side only.
Thanks,
Prasad Das
----------------------------------------------------------------
If the response is helpful, please click "**Mark as Best Response**" and like it. You can share your feedback via Microsoft Teams Developer Feedback link.