Open Closed

Create Tenant and User using API and call API from console App is giving Authentication error. #9237


User avatar
0
sghorakavi@cpat.com created

*Steps to reproduce the issue- Have a module app service with create tenant and created user. We call this app service method from endpoint API Call end point API from console app. Getting 401 authentication error. Tried to use Bearer token from Swagger, still same issue. Any suggestion?

ABP Version : 9.0.4 UI: MVC Database : SQL Tiered (MVC) or Auth Server Separated (Angular): Yes


3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share full debug logs?

    https://abp.io/support/questions/8622/How-to-enable-Debug-logs-for-troubleshoot-problems

    Thanks.

  • User Avatar
    0
    sghorakavi@cpat.com created

    Error is "UnAuthorized" var data = new { lmsTenantId = 111110, tenantName = "A_1Tenant", lmsUserId = 222122, lmsUserName = "B_User", firstName = "D", lastName = "F", password = "Sudha123#", email = "d@cpat.com" };

    var json = JsonSerializer.Serialize(data);

    var content = new StringContent(json, Encoding.UTF8, "application/json");

    var key = "6ef2b2d44c75e3919e90ea39d0992b77747095d64583730685b486a0c653b8f2f1b7c33ac8fa16facb2aa01fa74459e9"; // same as in server config var issuer = "ConsoleApp1"; var audience = "ConsoleApp1";

    var loginPayload = new { username = "admin", password = "1q2w3e*" };

    var content1 = new StringContent(JsonSerializer.Serialize(loginPayload), Encoding.UTF8, "application/json");

    using var client1 = new HttpClient { BaseAddress = new Uri("https://auth.cpat.com:44300/") };

    //var key = System.Text.Encoding.UTF8.GetBytes(key1);

    var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)); var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);

    var claims = new[] { new Claim(JwtRegisteredClaimNames.Sub, "console-app"), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim(ClaimTypes.NameIdentifier, "console-app-id") };

    var token = new JwtSecurityToken( issuer, audience, claims, expires: DateTime.UtcNow.AddHours(1), signingCredentials: credentials );

    var tokenString = new JwtSecurityTokenHandler().WriteToken(token); Console.WriteLine("Token:\n" + tokenString);

    using var client = new HttpClient(); client.BaseAddress = new Uri("https://auth.cpat.com:44300/"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "6ef2b2d44c75e3919e90ea39d0992b77747095d64583730685b486a0c653b8f2f1b7c33ac8fa16facb2aa01fa74459e9");

    // var response1 = await client.PostAsync("api/login", content1); //Console.WriteLine("LOGIN:"+ response1); //var resultJson1 = await response1.Content.ReadAsStringAsync(); //var token1 = JsonDocument.Parse(resultJson1).RootElement.GetProperty("token").GetString();

    var response = await client.PostAsync("api/lmsbridge/v1.0/lmsUserLogin", content); if (response.IsSuccessStatusCode) { var conten1t = await response.Content.ReadAsStringAsync(); Console.WriteLine("Response:\n" + conten1t); } else { Console.WriteLine("Error: " + response.StatusCode);

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Error is "UnAuthorized"

    Please share the full logs.txt. Include the identity model and OpenIddict logs.

    https://abp.io/support/questions/8622/How-to-enable-Debug-logs-for-troubleshoot-problems

    Thanks. liming.ma@volosoft.com

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on May 12, 2025, 05:22