• Home
  • Categories
  • Recent
  • Popular
  • Pricing
  • Contact us
  • Docs
  • Login
FusionAuth
  • Home
  • Categories
  • Recent
  • Popular
  • Pricing
  • Contact us
  • Docs
  • Login

Problems logging in user through C# API call

Scheduled Pinned Locked Moved
Q&A
3
16
6.4k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X
    xan
    last edited by xan 3 Sept 2021, 16:49 9 Mar 2021, 16:47

    Hi.

    I am trying to make a login for my BlazorServer app, but I am having a problem of the webbrowser throwing the bellow error.

    System.ArgumentNullException: Value cannot be null. (Parameter 'uriString')
       at System.Uri..ctor(String uriString)
       at io.fusionauth.DefaultRESTClient..ctor(String host)
       at io.fusionauth.DefaultRESTClientBuilder.build(String host)
       at io.fusionauth.FusionAuthClient.buildAnonymousClient()
       at io.fusionauth.FusionAuthClient.buildClient()
       at io.fusionauth.FusionAuthClient.LoginAsync(LoginRequest request)
       at Roots.FusionAuth.Users.FusionAuthUserManager.Login(String email, String password) in D:\Projects\GenoTech\Roots\Roots.FusionAuth\Levels\
    

    I can't find what field I am not setting, but for reference here is my login code.

    var loginRequest = new LoginRequest();
                
    Guid appID = new Guid();
    string? stringID = FusionAuthMgmtServerInfo.ApplicationId;
    if (Guid.TryParse(stringID, out appID)) { }
    else
        _log.LogError("Couldn't convert Application Id, string to Guid.");
                
    loginRequest.applicationId = appID;
    loginRequest.password = password;
    
    loginRequest.ipAddress = FusionAuthMgmtServerInfo.FusionauthUrl;
    
    Task<ClientResponse<LoginResponse>> loginTask;
    await (loginTask = _faClient.LoginAsync(loginRequest));
    
    var loginResponse = loginTask.Result;
    

    I was thinking it was the .ipAddress but since the library has no commenting I have been shooting in the dark most of the time with all this.

    D 1 Reply Last reply 11 Mar 2021, 00:14 Reply Quote 0
    • X
      xan
      last edited by 10 Mar 2021, 22:45

      I fallowed this tutorial
      https://fusionauth.io/blog/2020/05/06/securing-asp-netcore-razor-pages-app-with-oauth/
      should I see something when I do "http://localhost:5000", currently it just gets a "localhost refused to connect."?

      B 1 Reply Last reply 1 Aug 2022, 06:21 Reply Quote 0
      • D
        dan
        last edited by 11 Mar 2021, 00:12

        @xan ,

        If you are seeing localhost refused to connect that may mean the server hasn't started or that you have a firewall blocking access to that port.

        Did you start the server?

        https://github.com/FusionAuth/fusionauth-example-asp-netcore has the full codebase if you want to try to get it running before working through the tutorial.

        1 Reply Last reply Reply Quote 0
        • D
          dan
          last edited by 11 Mar 2021, 00:13

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • D
            dan @xan
            last edited by 11 Mar 2021, 00:14

            @xan said in Problems logging in user through C# API call:

            I was thinking it was the .ipAddress but since the library has no commenting I have been shooting in the dark most of the time with all this.

            How are you creating the client (_faClient) here? It looks like you might not be passing the host (which is typically at http://localhost:9011 if you are developing locally).

            1 Reply Last reply Reply Quote 0
            • X
              xan
              last edited by xan 3 Nov 2021, 01:08 11 Mar 2021, 00:45

              @dan said in Problems logging in user through C# API call:

              _faClient

              So _faClient is DIed. The service is setup here.

              services.AddTransient<IFusionAuthAsyncClient, FusionAuthClient>(_ =>
              {
                  return FusionAuthClientBuilder.Build(context.Configuration);
              });
              

              How do I check to see if the server has started? I have the firewall open on that port(in and out), and can login through the 9011 port.
              This is setup on a ec2 server, so I am using a static ip to make calls to it, and I have those specified in my User secrets, which looks like.

              {
                "UsersManagement":{
                  "ClientSecret" : "XXXX",
                  "ApiKey" : 	"XXXX",
                  "Server" : "http://xxx.xxx.xxx.xxx:9011",
                  "Authority" : "http://SAME.AS.ABOVE:9011",
                  "TenantId" : "XXXX",
                  "ApplicationId" : "XXXX",
                  "ClientID" : "SAME AS ABOVE"  }
              }
              

              Which looking at the example project you linked they have

              "SampleApp" : { 
                    "Authority" : "http://localhost:9011",
                    "CookieName" : "sampleappcookie",
                    "ClientId" : "4420013f-bc5e-4d5a-9f94-f4b64ad5107c"
                 }
              

              Does the json object have to be the name of the project, assembly, or namespace?
              EDIT: Ah nevermind they are specifying it in the AddOpenIdConnect, where instead I am using the Client Object.

              1 Reply Last reply Reply Quote 0
              • X
                xan
                last edited by xan 3 Nov 2021, 01:21 11 Mar 2021, 00:50

                This is where I build the FusionAuth Client.

                public static FusionAuthClient FusionAuth;
                public static FusionAuthClient Build(IConfiguration configuration)
                {
                    if (FusionAuth == null)
                        FusionAuth = new FusionAuthClient(
                            apiKey:configuration.GetConnectionString(FusionAuthMgmtServerInfo.ApiKey),
                            host:configuration.GetConnectionString(FusionAuthMgmtServerInfo.FusionauthUrl),
                            tenantId:configuration.GetConnectionString(FusionAuthMgmtServerInfo.TenantId));
                    return FusionAuth;
                }
                

                which just are the ""UsersManagement:ApiKey", "UserManagement:Server", "UserManagement:ClientID"

                EDIT:
                Also in the webportal admin page for the application my "Authorized redirect URLs" is "http://xxx.xxx.xxx.xxx:5000/signin-oidc"(with the xxx being the servers public static ipv4), and "LogoutURL" as "http://xxx.xxx.xxx.xxx:5000"

                If I look at the application details it shows.

                OAuth IdP login URL:	 http://localhost:9011/oauth2/authorize?client_id=[CLIENTID]&response_type=code&redirect_uri=http%3A%2F%2F[SERVERIpv4]%3A5000%2Fsignin-oidc
                Logout URL:	         http://localhost:9011/oauth2/logout?client_id=[CLIENTID]
                Introspect endpoint:	 http://localhost:9011/oauth2/introspect
                Token endpoint:	         http://localhost:9011/oauth2/token
                Userinfo endpoint:	 http://localhost:9011/oauth2/userinfo
                Device endpoint:	 http://localhost:9011/oauth2/device_authorize
                OpenID Connect Discovery:http://localhost:9011/.well-known/openid-configuration/[TENANT_ID]
                JSON Web Key (JWK) Set:	 http://localhost:9011/.well-known/jwks.json
                

                with [] being what they should be(excluded by me).

                1 Reply Last reply Reply Quote 0
                • X
                  xan
                  last edited by 11 Mar 2021, 06:02

                  Though it looks like I have two applications, a base FusionAuth and then my applications, both using the same localhost:9011. How does it seperate them out? And if I need to change that where do I do that?

                  1 Reply Last reply Reply Quote 0
                  • X
                    xan
                    last edited by xan 3 Dec 2021, 21:25 12 Mar 2021, 21:25

                    Any suggestions on how to proceed, or is this a bug I should report?

                    1 Reply Last reply Reply Quote 0
                    • X
                      xan
                      last edited by 13 Mar 2021, 22:33

                      A new update. I can do a get user by email, but if I try to do user login both sync and async it throws a 404 status code. So clearly it is finding the server, maybe it just can't find the login portal?

                      1 Reply Last reply Reply Quote 0
                      • X
                        xan
                        last edited by xan 14 Mar 2021, 00:01

                        I got it working in a separate console app, so must be something in my app.

                        1 Reply Last reply Reply Quote 0
                        • X
                          xan
                          last edited by 14 Mar 2021, 00:41

                          Yep, I wasn't assigning the values correctly for the service. All fixed!

                          1 Reply Last reply Reply Quote 1
                          • D
                            dan
                            last edited by 15 Mar 2021, 13:39

                            @xan So glad you got it resolved!

                            Was there documentation that should be clearer or any changes needed on our end to avoid other folks having the issues you encountered?

                            X 1 Reply Last reply 18 Mar 2021, 02:55 Reply Quote 0
                            • X
                              xan @dan
                              last edited by xan 18 Mar 2021, 02:55

                              @dan

                              @dan said in Problems logging in user through C# API call:

                              e

                              The ultimate help ended up being this
                              https://github.com/FusionAuth/fusionauth-netcore-client/blob/master/fusionauth-netcore-client-test/fusionauth-netcore-client-test/test/io/fusionauth/FusionAuthClientTest.cs
                              which went over each functionality which was nice. Otherwise comments of functions on the API would be nice as at points it is a bit unclear. Honestly this was the only problem I have faced so far(and it was just my fault in the end), and it has been an amazing tool.

                              1 Reply Last reply Reply Quote 1
                              • D
                                dan
                                last edited by 18 Mar 2021, 17:43

                                Thanks, that's great to hear!

                                We have a long term project to overhaul the client libraries but it's on hold for right now. Appreciate the feedback.

                                1 Reply Last reply Reply Quote 0
                                • B
                                  bradmacer @xan
                                  last edited by 1 Aug 2022, 06:21

                                  @xan said in Problems logging in user through C# API call:

                                  when I do "http://localhost:5000", currently it just gets a "localhost refused to connect."?

                                  Generally this happens when the service running on your localhost has some problem resolving the request. If you have access to logs, please see logs for more details on the error. Also, make sure the application interface, server, and services are running. There are many situations that might trigger “this site can't be reached” error in browsers. Sometimes the server is still running but the interface application is closed or the database is down. If your application interface and server is up but a dependent service is down then restart your computer/server and restart services. Make sure the app is bound to localhost. It may just be bound to an individual interface. netstat -na will give you the clues you need. Run a port scan on your computer and make sure the port is opened.

                                  The problem may happens for failing on DNS lookup . DNS is that network address that translates the website name to its internet address. Most often it causes for not getting the internet connection or misconfigured internet or network settings. Another reason could be the firewall preventing Google Chrome to load the webpage. However, other reasons, such as insufficient permissions or the Apache web server not running properly might also cause the error.

                                  1 Reply Last reply Reply Quote -1
                                  • First post
                                    Last post