Aperto Chiuso

UNAUTHORIZED_CLIENT after deploying to test server. #524


User avatar
0
GregB creato

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

  • ABP Framework version: v3.3.0
  • UI type: Angular
  • Tiered (MVC) or Identity Server Seperated (Angular): no
  • Exception message and stack trace:

500 Internal Server Error UNAUTHORIZED_CLIENT

2020-11-02 11:04:48.240 +00:00 [ERR] Invalid redirect_uri: https://dev-web.example.com/ {"ClientId":"Example_App","ClientName":"Example_App","RedirectUri":null,"AllowedRedirectUris":["https://dev-api.example.com","https://dev-web.example.com"],"SubjectId":"anonymous","ResponseType":null,"ResponseMode":null,"GrantType":null,"RequestedScopes":"","State":null,"UiLocales":null,"Nonce":null,"AuthenticationContextReferenceClasses":null,"DisplayMode":null,"PromptMode":null,"MaxAge":null,"LoginHint":null,"SessionId":null,"Raw":{"response_type":"code","client_id":"Example_App","state":"MldHMGt1TnZkS0ItcnBXQzU1WGROck9LTWp5MGlzdFJEdjV0UE9sMS5DUjdD","redirect_uri":"https://dev-web.example.com/","scope":"openid offline_access Example","code_challenge":"vXXK9P8NZ7zMPbzktJetY4amyp5F1sqWU-rYTpQPJ3c","code_challenge_method":"S256","nonce":"MldHMGt1TnZkS0ItcnBXQzU1WGROck9LTWp5MGlzdFJEdjV0UE9sMS5DUjdD"},"$type":"AuthorizeRequestValidationLog"}

  • Steps to reproduce the issue:
  1. I've added a "development" environment to the Angular project, changing the values like so
import { Config } from '@abp/ng.core';

const baseUrl = 'https://dev-web.example.com/';

export const environment = {
  production: true,
  application: {
    baseUrl,
    name: 'Example',
  },
  oAuthConfig: {
    issuer: 'https://dev-api.example.com',
    redirectUri: baseUrl,
    clientId: 'Example_App',
    responseType: 'code',
    scope: 'offline_access Example',
  },
  apis: {
    default: {
      url: 'https://dev-api.example.com',
      rootNamespace: 'Example',
    },
  },
} as Config.Environment;

  1. I've added a new task to the package and run it. "build:dev": "ng build --configuration development" and yarn build:dev
  2. I've copied the DbMigrator to my server. Updated appsettings.json as follows and run the migrator
{
    "ConnectionStrings": {
      "Default": "Server=localhost\\sqlexpress;Database=Example-Dev;Trusted_Connection=True;MultipleActiveResultSets=true"
    },
    "IdentityServer": {
      "Clients": {
        "Example_Web": {
          "ClientId": "Example_Web",
          "RootUrl": "https://dev-web.example.com/"
        },
        "Example_App": {
          "ClientId": "Example_App",
          "RootUrl": "https://dev-api.example.com/"
        },
        "Example_Blazor": {
          "ClientId": "Example_Blazor",
          "RootUrl": "https://localhost:44307"
        }
      }
    },
    "AbpLicenseCode": "..."
  }
  
  1. I've deployed the API project with matching values in the appsettings.json
{
  "App": {
    "SelfUrl": "https://dev-api.example.com/",
    "ClientUrl": "https://dev-web.example.com/",
    "CorsOrigins": "http://dev-web.example.com/,https://dev-web.example.com/"
  },
  "ConnectionStrings": {
    "Default": "Server=localhost\\SQLExpress;Database=Example-Dev;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "AuthServer": {
    "Authority": "https://dev-api.example.com",
    "RequireHttpsMetadata": "true"
  },
}

The Issue I can browse the Swagger document and the Angular app fine, but when I try to log in I get the error screen from the API stating
500 Internal Server Error UNAUTHORIZED_CLIENT

and the following messages in the log 2020-11-02 11:04:48.240 +00:00 [ERR] Invalid redirect_uri: https://dev-web.example.com/ {"ClientId":"Example_App","ClientName":"Example_App","RedirectUri":null,"AllowedRedirectUris":["https://dev-api.example.com","https://dev-web.example.com"],"SubjectId":"anonymous","ResponseType":null,"ResponseMode":null,"GrantType":null,"RequestedScopes":"","State":null,"UiLocales":null,"Nonce":null,"AuthenticationContextReferenceClasses":null,"DisplayMode":null,"PromptMode":null,"MaxAge":null,"LoginHint":null,"SessionId":null,"Raw":{"response_type":"code","client_id":"Example_App","state":"MldHMGt1TnZkS0ItcnBXQzU1WGROck9LTWp5MGlzdFJEdjV0UE9sMS5DUjdD","redirect_uri":"https://dev-web.example.com/","scope":"openid offline_access Example","code_challenge":"vXXK9P8NZ7zMPbzktJetY4amyp5F1sqWU-rYTpQPJ3c","code_challenge_method":"S256","nonce":"MldHMGt1TnZkS0ItcnBXQzU1WGROck9LTWp5MGlzdFJEdjV0UE9sMS5DUjdD"},"$type":"AuthorizeRequestValidationLog"}

What's wrong, and what is the processess for deploying an appilcation to a live environment?


6 risposte
  • User Avatar
    0
    liangshiwei creato
    Team di supporto Fullstack Developer

    Hi,

    You are using Example_App client. I think the appsettings.json should be :

    "IdentityServer": {
        "Clients": {
         "Example_Web": {
              "ClientId": "Example_Web",
              "RootUrl": "https://localhost:44362"   // Example_Web is not important, because you never use it 
           },
          "Example_App": {
              "ClientId": "Example_App",
              "RootUrl": "https://dev-web.example.com/"
           },
         "Example_Blazor": {
              "ClientId": "Example_Blazor",
              "RootUrl": "https://localhost:44307"
           }
        }
      }
    
  • User Avatar
    0
    GregB creato

    Hi @liangshiwei,

    I've deleted the database, changed the migrator appsettings.json as you describe and re-run the migrator against a new empty database and the problem persists.

  • User Avatar
    0
    liangshiwei creato
    Team di supporto Fullstack Developer

    Can you share some screenshots and error logs?

  • User Avatar
    0
    GregB creato

    Can I share those privately?

  • User Avatar
    0
    liangshiwei creato
    Team di supporto Fullstack Developer

    Of course. my email : shiwei.liang@volosoft.com

  • User Avatar
    0
    liangshiwei creato
    Team di supporto Fullstack Developer

    "RootUrl": "https://dev-web.example.com/" should be "RootUrl": "https://dev-web.example.com"

    Because of the backslash in your configuration. The problem has been solved, so I close this question.

Made with ❤️ on ABP v8.2.0-preview Updated on marzo 25, 2024, 15:11