Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Connecting Externally #5761


User avatar
0
20summers created

I am trying to wtite an Outlook addin that communicated with the main application.

When I run the Console API Client on local - everyhting works great.

When I change the following line: ServerUrlBase = "http://www.brokerblocks.com/" in the client and try to connect to my azure hosting, it fails on this line:

var tokenClient = new TokenClient(disco.TokenEndpoint, "client", "def2edf7-5d42-4edc-a84a-30136c340e13", httpHandler);

Is there something I am missing?


8 Answer(s)
  • User Avatar
    0
    ryancyq created
    Support Team

    which version of AspNetZero you are using?

    Can you check for the errors in Log.txt?

    Also, please share the network request details.

  • User Avatar
    0
    20summers created

    Hi Using Jquery Core 6.0

  • User Avatar
    0
    ryancyq created
    Support Team

    Can you check for the errors in Log.txt?

    The log file is located at App_Data/Log.txt by default.

  • User Avatar
    0
    20summers created

    Hi,

    I changes this line: var disco = await DiscoveryClient.GetAsync(ServerUrlBase);

    to

    var client = new DiscoveryClient(ServerUrlBase); client.Policy.RequireHttps = false; var disco = await client.GetAsync();

    it now got past the error I initially had.

  • User Avatar
    0
    20summers created

    Hi,

    I get the following error when running: var response = await client.GetAsync($"{ServerUrlBase}api/services/app/user/getUsers");

    {StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent, Headers: { Set-Cookie: ARRAffinity=cc4fc0641acacdbd47034dfe96d9c4c9945c09945e68ea4d6752ff5973ae6619;Path=/;HttpOnly;Domain=www.brokerblocks.com Date: Fri, 12 Oct 2018 13:14:25 GMT Content-Length: 0 }}

  • User Avatar
    0
    ryancyq created
    Support Team

    500 Internal Error should have error stack trace at App_Data/Log.txt.

    Can you share it?

  • User Avatar
    0
    20summers created
    INFO  2018-10-13 07:40:18,860 [78   ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 902.0965ms 200 text/html; charset=utf-8
    INFO  2018-10-13 07:44:51,345 [36   ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://www.brokerblocks.com/.well-known/openid-configuration  
    INFO  2018-10-13 07:44:51,433 [36   ] Server4.Hosting.IdentityServerMiddleware - Invoking IdentityServer endpoint: IdentityServer4.Endpoints.DiscoveryEndpoint for /.well-known/openid-configuration
    INFO  2018-10-13 07:44:51,484 [36   ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 139.8698ms 200 application/json; charset=UTF-8
    INFO  2018-10-13 07:44:51,982 [36   ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://www.brokerblocks.com/.well-known/openid-configuration/jwks  
    INFO  2018-10-13 07:44:52,008 [36   ] Server4.Hosting.IdentityServerMiddleware - Invoking IdentityServer endpoint: IdentityServer4.Endpoints.DiscoveryKeyEndpoint for /.well-known/openid-configuration/jwks
    INFO  2018-10-13 07:44:52,020 [36   ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 38.1774ms 200 application/json; charset=UTF-8
    INFO  2018-10-13 07:44:53,017 [102  ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 POST http://www.brokerblocks.com/connect/token application/x-www-form-urlencoded 56
    INFO  2018-10-13 07:44:53,057 [102  ] Server4.Hosting.IdentityServerMiddleware - Invoking IdentityServer endpoint: IdentityServer4.Endpoints.TokenEndpoint for /connect/token
    INFO  2018-10-13 07:44:54,262 [102  ] tIdentity.ResourceOwnerPasswordValidator - Credentials validated for username: admin
    INFO  2018-10-13 07:44:54,289 [102  ] Server4.Validation.TokenRequestValidator - Token request validation success
    {
      "ClientId": "client",
      "GrantType": "password",
      "Scopes": "default-api",
      "UserName": "admin",
      "Raw": {
        "grant_type": "password",
        "username": "admin",
        "password": "***REDACTED***"
      }
    }
    INFO  2018-10-13 07:44:54,462 [102  ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 1444.7529ms 200 application/json; charset=UTF-8
    INFO  2018-10-13 07:44:54,964 [102  ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://www.brokerblocks.com/api/services/app/user/getUsers  
    INFO  2018-10-13 07:44:55,004 [102  ] uthentication.JwtBearer.JwtBearerHandler - Failed to validate the token.
    Microsoft.IdentityModel.Tokens.SecurityTokenSignatureKeyNotFoundException: IDX10501: Signature validation failed. Unable to match keys: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]', 
    token: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]'.
       at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateSignature(String token, TokenValidationParameters validationParameters)
       at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateToken(String token, TokenValidationParameters validationParameters, SecurityToken& validatedToken)
       at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
    INFO  2018-10-13 07:44:55,037 [102  ] uthentication.JwtBearer.JwtBearerHandler - Bearer was not authenticated. Failure message: IDX10501: Signature validation failed. Unable to match keys: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]', 
    token: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]'.
    ERROR 2018-10-13 07:44:55,135 [30   ] uthentication.JwtBearer.JwtBearerHandler - Exception occurred while processing message.
    System.InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]'. ---> System.IO.IOException: IDX20804: Unable to retrieve document from: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]'. ---> System.Net.Http.HttpRequestException: An attempt was made to access a socket in a way forbidden by its access permissions ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions
       at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
       --- End of inner exception stack trace ---
       at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
       at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
       at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
       at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
       at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
       at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
       at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
       at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
       --- End of inner exception stack trace ---
       at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
       at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
       at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
       --- End of inner exception stack trace ---
       at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
       at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
    ERROR 2018-10-13 07:44:55,277 [30   ] e.Diagnostics.ExceptionHandlerMiddleware - An unhandled exception has occurred while executing the request.
    System.InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]'. ---> System.IO.IOException: IDX20804: Unable to retrieve document from: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]'. ---> System.Net.Http.HttpRequestException: An attempt was made to access a socket in a way forbidden by its access permissions ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions
       at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
       --- End of inner exception stack trace ---
       at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
       at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
       at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
       at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
       at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
       at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
       at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
       at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
       --- End of inner exception stack trace ---
       at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
       at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
       at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
       --- End of inner exception stack trace ---
       at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
       at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
       at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
       at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
       at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
       at IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler.HandleAuthenticateAsync()
       at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
       at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
       at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
       at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)
    INFO  2018-10-13 07:44:55,327 [30   ] uthentication.JwtBearer.JwtBearerHandler - Bearer was not authenticated. Failure message: IDX10501: Signature validation failed. Unable to match keys: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]', 
    token: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]'.
    ERROR 2018-10-13 07:44:55,328 [30   ] e.Diagnostics.ExceptionHandlerMiddleware - An exception was thrown attempting to execute the error handler.
    System.InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]'. ---> System.IO.IOException: IDX20804: Unable to retrieve document from: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]'. ---> System.Net.Http.HttpRequestException: An attempt was made to access a socket in a way forbidden by its access permissions ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions
       at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
       --- End of inner exception stack trace ---
       at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
       at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
       at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
       at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
       at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
       at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
       at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
       at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
       --- End of inner exception stack trace ---
       at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
       at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
       at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
       --- End of inner exception stack trace ---
       at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
       at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
       at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
       at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
       at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
       at IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler.HandleAuthenticateAsync()
       at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
       at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
       at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
       at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)
    ERROR 2018-10-13 07:44:55,340 [30   ] Microsoft.AspNetCore.Server.Kestrel      - Connection id "0HLHG4MDOKBF7", Request id "0HLHG4MDOKBF7:00000004": An unhandled exception was thrown by the application.
    
  • User Avatar
    0
    20summers created

    Ok - so I feel stupid.

    Had not changed the appSettings.production.json to reflect the main domain.

    Changed the following - and now it works

    "IdentityServer": { "IsEnabled": "true", "Authority": "http://www.brokerblocks.com",