Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Enhancement][L] Enable OBO for SP (ADAL to MSAL Migration Issue) #1845

Closed
4 tasks done
niruatweb opened this issue May 25, 2020 · 12 comments
Closed
4 tasks done

[Enhancement][L] Enable OBO for SP (ADAL to MSAL Migration Issue) #1845

niruatweb opened this issue May 25, 2020 · 12 comments

Comments

@niruatweb
Copy link

niruatweb commented May 25, 2020

Work

  • See Penguinwizzard@de00f61 for a solution
  • Evaluate if solution will work, e.g. token cache
  • Create an E2E test using PPE env where this is allowed.

Which Version of MSAL are you using ?
4.13.0. I have described the issue in stack overflow. https://stackoverflow.microsoft.com/questions/198842. Generating OBO for SPN fails with "client info is null"

Platform
net45

What authentication flow has the issue?

  • Web API
    • OBO for SPNs

Other? - please describe;
OBO for users work fine but not for groups.

Is this a new or existing app?
YES

Repro

  new UserAssertion(userBearerToken, "urn:ietf:params:oauth:grant-type:jwt-bearer"))
    .WithAuthority(aadAuthenticationAuthority)
    .ExecuteAsync();

==== Complete Stack Trace ===
Microsoft.Identity.Client.MsalClientException: client info is null
   at Microsoft.Identity.Client.Core.ClientInfo.CreateFromJson(String clientInfo)
   at Microsoft.Identity.Client.Internal.Requests.RequestBase.<CacheTokenResponseAndCreateAuthenticationResultAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Identity.Client.Internal.Requests.OnBehalfOfRequest.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Identity.Client.Internal.Requests.RequestBase.<RunAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Identity.Client.ApiConfig.Executors.ConfidentialClientExecutor.<ExecuteAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Rdx.GatewayService.Engine.Authentication.AadApplicationAuthenticator.<AcquireTokenAsync>d__7.MoveNext() in E:\CXTLRepos\TSI\Backend\Source\Product\GatewayService\Engine\Authentication\AadApplicationAuthenticator.cs:line 57”

Expected behavior
OBO should be generated

Actual behavior
Exception. Response comes from token endpoint but fails during deserialization of response.

Possible Solution
Fix in the requestBase.cs

Additional context/ Logs / Screenshots
Add any other context about the problem here, such as logs and screebshots. Logging is described at https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/logging

@jmprieur
Copy link
Contributor

@niruatweb: there is no user with a SP. it's not possible to use a UserAssertion?

@niruatweb
Copy link
Author

niruatweb commented May 25, 2020

Hi @jmprieur , but how would i be able to get groups of the spn in this case. Can't i get an groups of SPN or deamon app?

@dkershaw10
Copy link

@niruatweb Are you trying to find the groups that the service principal owns, or something else? Please clarify.

@niruatweb
Copy link
Author

@dkershaw10 i am trying find the group ids of which service principal is part of.

@dkershaw10
Copy link

Gotcha - so you want all the groups that the service principal is a member of. Microsoft Graph can give you this answer.
See https://docs.microsoft.com/en-us/graph/api/serviceprincipal-list-memberof?view=graph-rest-1.0&tabs=http OR https://docs.microsoft.com/en-us/graph/api/serviceprincipal-list-transitivememberof?view=graph-rest-1.0&tabs=http

If you are looking for this information to show up as a claim in the access token, I don't know if that is supported. We'd have to get others involved who work on the Identity STS. It would be worth creating a new and separate question on Microsoft Stack Overflow for that.

@niruatweb
Copy link
Author

Groups are coming as part of access token. I believe i still need to pass OBO in this case. I hope MSAL bug to get OBO will be fixed soon.

@niruatweb
Copy link
Author

niruatweb commented May 27, 2020

Hi @jmprieur I have three options to generate OBO,

  1. Wait for your fix for MSAL.
  2. Use ADAL for this scenario only. I haven't tried if ADAL works
  3. Call OAuth directly?. Creating client assertion is tricky, it is handled properly in MSAL library. I have to copy some of that code.

I will go with one of the option based on the time it would take for MSAL fix. What is your suggestion? How many days does it take?

@jmprieur
Copy link
Contributor

cc: @henrik-me, @bgavrilMS, @trwalke @neha-bhargava
@niruatweb : do you have a repro that you could share with us (app coordinates)?
(Jean-Marc.Prieur at Microsoft dot com)

@bgavrilMS bgavrilMS added this to the Ongoing Customer Help milestone May 27, 2020
@bgavrilMS bgavrilMS removed this from the Ongoing Customer Help milestone May 27, 2020
@niruatweb
Copy link
Author

@jmprieur Below is the code, let me know if you want that cert that i am pointing as thumbprint.

''' var _confidentialClientApp = MSAL.ConfidentialClientApplicationBuilder
.Create((string)"4370834b-eb27-4dfc-b2cc-4028b4d82d1c") .WithCertificate(GetCertificateByThumbprint("766D2D978F190227EF13D066048E160029D39BA5"))
.Build();

        string aadAuthenticationAuthority = StringUtils.FormatInvariant("{0}/{1}/oauth2/authorize?resource={2}", "https://#.windows-ppe.net", "f686d426-8d16-42db-81b7-ab578e110ccd", "120d688d-1518-4cf7-bd38-182f158850b6");

       IReadOnlyList <string> scopes = new List<string>() { "120d688d-1518-4cf7-bd38-182f158850b6/.default" };

    var authenticationResult = await _confidentialClientApp.AcquireTokenForClient(scopes)
            .WithAuthority(aadAuthenticationAuthority)
                                        .ExecuteAsync();
        string userToken = authenticationResult.AccessToken;

        var _confidentialApp = MSAL.ConfidentialClientApplicationBuilder
            .Create((string)"120d688d-1518-4cf7-bd38-182f158850b6")
            .WithCertificate(GetCertificateByThumbprint("766D2D978F190227EF13D066048E160029D39BA5"))
            .Build();

        scopes = new List<string>() { "User.ReadBasic.All", "GroupMember.Read.All" };

        aadAuthenticationAuthority = StringUtils.FormatInvariant("{0}/{1}/oauth2/authorize?resource={2}", "https://#.windows-ppe.net", "f686d426-8d16-42db-81b7-ab578e110ccd", "https://graph.microsoft-ppe.com/");
        authenticationResult = await _confidentialApp.AcquireTokenOnBehalfOf(TestConstants.scopes, new MSAL.UserAssertion(userToken, "urn:ietf:params:oauth:grant-type:jwt-bearer"))
            .WithAuthority(aadAuthenticationAuthority)
                                        .ExecuteAsync();'''

@trwalke trwalke added this to the Future Minor Version Update milestone Sep 3, 2020
@trwalke trwalke removed their assignment Nov 13, 2020
@henrik-me henrik-me changed the title [Bug] OBO for spns fails [Enhancement] Enable OBO for SP (ADAL to MSAL Migration Issue) Jan 28, 2021
@jmprieur
Copy link
Contributor

See possible solution: Penguinwizzard@de00f61

@bgavrilMS @henrik-me can we add this to the following release?

@jmprieur
Copy link
Contributor

@jmprieur to provide API review doc for this

@bgavrilMS bgavrilMS changed the title [Enhancement] Enable OBO for SP (ADAL to MSAL Migration Issue) [Enhancement][L] Enable OBO for SP (ADAL to MSAL Migration Issue) Mar 17, 2021
@jmprieur
Copy link
Contributor

jmprieur commented Mar 17, 2021

If we want to test this, we can/should use PPE

daemon app calls web API call graph. The web API calls graph on behalf of the daemon

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

6 participants