Closed parttimer777 closed 3 years ago
Take a look at the documentation for the ROPC workflow. Have you triple checked the username and password? (have to ask)
https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth-ropc#error-response
Are you you using the same user and client application as the one you're using in C#? Are you using the same auth flow in C#? I'm curious, why do you have a C# app and a Java app?
Is MFA enabled for the user? Is this a hybrid environment where the user is in an on-premise AD? If so, this flow won't work.
Correct, this is a hybrid environment and the user is in an on-prem AD. The 2 apps (java and c#) are both on-prem. The app-reg is setup as a desktop "platform" with "urn:ietf:wg:oauth:2.0:oob" as the redirect URI. I'm inclined to believe it won't work; I'm just confused as to why the c# one works. Does the msgraph c# lib behave differently? Like does it hook into the IIS integrated auth...? (wild guess)
I'm confused on why the c# one works too. . Have you captured and compared the requests/response between both clients? What do you see?
Are you suggesting to wireshark and compare? i guess it's coming to that... im not sure how to do that with encrypted traffic but i will try...
Just verified the app-reg settings: Platform: "Mobile and desktop applications" Redirect uris: "urn:ietf:wg:oauth:2.0:oob" Implicit grant: "ID Tokens" Allow public client flows: "Yes"
Here's the c# code that absolutely works:
var ClientId= "-----------------";
var Scopes = new string[] { "https://graph.microsoft.com/User.Read" };
var UserName = "-----------";
var Password = "-----------------";
var TenantId = "-------------";
IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
.Create(ClientId)
.WithTenantId(TenantId)
.Build();
// Create an authentication provider by passing in a client application and graph scopes.
IEnumerable<string> scopes = Scopes;
SecureString pwd = new SecureString();
foreach (var ch in Password)
pwd.AppendChar(ch);
Task<AuthenticationResult> task1 = publicClientApplication.AcquireTokenByUsernamePassword(scopes, UserName, pwd).ExecuteAsync();
task1.Wait();
IAuthenticationProvider authProvider = new UsernamePasswordProvider(publicClientApplication, scopes);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
User me = await graphClient.Me.Request()
.GetAsync();
Console.WriteLine(me.DisplayName);
Yeah, its what I'd have to do at this point as I'm not well enough versed with identity scenarios. Hey, I wonder if identity has issue with you setting CLIENT_SECRET
in the UsernamePasswordProvider. Can you leave those out?
Are you using the same clientId for both C# and Java?
Correct, same clientId/appReg. Nulling the client_secret and trying the 4 param constructor version of UsernamePasswordProvider has no effect.
Just fiddler'ed the c# app a second ago. It does a discovery request on the provided username and gets the internal network saml auth service url. Then it makes a request to the saml auth service to get the bearer assertion token. Then finally it requests the MS Graph oauth url with the saml bearer assertion token to get the graph access token.
keywords for this is "MSAL" "SAML Bearer assertion flow" does this sound familiar? any chance this lib supports that?
This library likely does not support it. It was created before MSAL for Java was available. I assume that MSAL for Java supports this.
We need to use MSAL within an implementation of IAuthenticationProvider and ICoreAuthenticationProvider.
Ok thanks. For people who will see this thread, a possible solution is to create a C# webapp where you specify the username/pass and it will return you the graph access token. I'll close this issue.
FYI the work Michael is mentioning is ongoing here https://github.com/microsoftgraph/msgraph-sdk-java-core/pull/42
Hi - I have an app reg setup in azure and c# code that works and now i'm trying to do the same thing in java with issues.
The app reg is setup with delegate permissions. Might someone have any recommendations as to what is causing this? Is it possible to have it display the auth token in order to troubleshoot better?