question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Help] I am using the method AcquireTokenByUsernamePassword to get the token, but I get the following error. I haven't configured it properly. thank you

See original GitHub issue

I am using the method AcquireTokenByUsernamePassword to get the token, but I get the following error. I haven’t configured it properly. thank you

Microsoft.Identity.Client:Version=“4.49.1”

code: public readonly static string[] ApiScopes = { “openid”, “profile”, “offline_access”, “User.ManageIdentities.All”, “User.Read.All”,“User.ReadBasic.All”,“User.Invite.All”,“User.ReadWrite.All”,“IdentityProvider.Read.All” };

app = PublicClientApplicationBuilder.Create(ClientId) .WithB2CAuthority(AuthoritySignUpSignIn) .WithRedirectUri(“http://localhost:8080/home”) .WithExtraQueryParameters(new Dictionary<string, string>() { { “nonce”, Guid.NewGuid().ToString() } }) .WithLogging(Log, LogLevel.Info, false) .Build();

authResult = await app.AcquireTokenByUsernamePassword(App.ApiScopes, “UserName”, “UserPassword”).ExecuteAsync();

Error Message: Error Acquiring Token: Microsoft.Identity.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path ‘’, line 0, position 0. at Microsoft.Identity.Json.JsonTextReader.ParseValue() at Microsoft.Identity.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter) at Microsoft.Identity.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Microsoft.Identity.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Microsoft.Identity.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Microsoft.Identity.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at Microsoft.Identity.Client.Utils.JsonHelper.DeserializeFromJson[T](String json) at Microsoft.Identity.Client.OAuth2.OAuth2Client.CreateResponse[T](HttpResponse response, RequestContext requestContext) at Microsoft.Identity.Client.OAuth2.OAuth2Client.ExecuteRequestAsync[T](Uri endPoint, HttpMethod method, RequestContext requestContext, Boolean expectErrorsOn200OK, Boolean addCommonHeaders, Func2 onBeforePostRequestData) at Microsoft.Identity.Client.OAuth2.OAuth2Client.GetTokenAsync(Uri endPoint, RequestContext requestContext, Boolean addCommonHeaders, Func2 onBeforePostRequestHandler) at Microsoft.Identity.Client.OAuth2.TokenClient.SendHttpAndClearTelemetryAsync(String tokenEndpoint, ILoggerAdapter logger) at Microsoft.Identity.Client.OAuth2.TokenClient.SendTokenRequestAsync(IDictionary`2 additionalBodyParameters, String scopeOverride, String tokenEndpointOverride, CancellationToken cancellationToken) at Microsoft.Identity.Client.Internal.Requests.UsernamePasswordRequest.GetTokenResponseAsync(CancellationToken cancellationToken) at Microsoft.Identity.Client.Internal.Requests.UsernamePasswordRequest.ExecuteAsync(CancellationToken cancellationToken) at Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync(CancellationToken cancellationToken) at Microsoft.Identity.Client.ApiConfig.Executors.PublicClientExecutor.ExecuteAsync(AcquireTokenCommonParameters commonParameters, AcquireTokenByUsernamePasswordParameters usernamePasswordParameters, CancellationToken cancellationToken)

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
bgavrilMScommented, Dec 28, 2022

Still, one can argue that MSAL should throw a friendlier exception and not a JSON parsing error. I would recommend treating this as a bug.

@kou-h - a few thoughts:

  1. You can’t ask for Graph scopes with a B2C user. Graph only works with Azure AD authority
  2. Username / Password is insecure because apps should not handle passwowrds. But apart from that, the flow will not work with MFA. So please use AcquireTokenInteractive instead.
  3. Can you capture a network trace and send it over? Use bogavril at microsoft.com
0reactions
bgavrilMScommented, Feb 1, 2023

@SameerK-MSFT - not sure why this matters? It’s just about throwing a better exception if folks attempt ROPC with B2C authority and graph scope.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Documentation] AcquireTokenByUsernamePassword ...
I am trying out AcquireTokenByUsernamePassword to get an access token but I get the following error: Microsoft.Identity.Client.
Read more >
Acquire a token to call a web API using username and ...
Learn how to build a desktop app that calls web APIs to acquire a token for the app using username and password.
Read more >
How to get OAuth2 access token for EWS managed API in ...
So, I need to find a way to get valid access token for service/daemon application to use with EWS managed API. My findings....
Read more >
Troubleshoot Azure AD Self Service Password Reset Error
You can't reset your own password because password reset isn't properly set up for your organization. You must contact your administrator to ...
Read more >
Acquire_token_by_username_p...
I have implemented the necessary structure to authenticate a user and retrieve its token with acquire_token_silent() method.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found