Search code examples
c#asp.net-core-mvcnativescriptidentityserver4

Identity Server 4/nativescript Hangs


I have the following client:

new Client
{
    ClientId = "nativeapptest",
    ClientName = "Native App Test",
    Enabled = true,
    RequireClientSecret = false,
    AllowedGrantTypes = GrantTypes.Code,
    RedirectUris = { "com.mysite.nativeapp.12365789785256-buv2dwer7jjjjv5fckasdftn367psbrlb:/home" },
    AllowedScopes =
    {
        IdentityServerConstants.StandardScopes.OpenId,
        IdentityServerConstants.StandardScopes.Profile,
        "MyScope"
    },
    RequirePkce = false,
    AllowOfflineAccess = true,
    RequireConsent = false
}

I am using native-script to build an android app that can log in with Identity Server 4. What currently happens is that I make a request to IS4 by opening a browser and using all the correct OpenID configuration and I end up on the login screen which then I choose to login with Google. Once on google, I enter my email and password and its all good and then Google tries to send me back to my site but it just hangs... Its a white page with nothing loaded and its just sits there forever, there are no error messages logged by is4 as far as I can tell.

The login part above for nativescript is from OAutho2 library https://www.npmjs.com/package/nativescript-oauth2

I'm trying to understand would this be a problem on the IS4 or the native Android application. Is the page hanging because it is waiting on the android application to take over having the login have worked? Mabye the problem is with the RedirectURI Scheme?

The URL it hangs on is as follows:

http://login.mysite.com/connect/authorize?client_id=nativeapptest&response_type=code&redirect_uri=com.mysite.nativeapp.12365789785256-buv2dwer7jjjjv5fckasdftn367psbrlb%3A%2Fhome&scope=openid%20profile%20MySite&response_mode=query&st

EDIT:

Since I'm running this on the actual server, I can't debug it directly, however, I did add logs to see how far the code goes. My logs tell me that the user was logged in by google and my system and my logs also show that ExternalCallback has redirected the page to

/connect/authorize/callback?client_id=nativeapptest&response_type=code&redirect_uri=com.mysite.nativeapp%3A%2F%2Fhome&scope=openid%20profile%20MyScope&response_mode=query&state=abcd

At this point, the page hangs.

Please note that we changed RedirectUri to com.mysite.nativeapp to help with testing.

Lastly, I'm not sure if it matters, but we are not using https as this is still development phase.


Solution

  • just finsed the sample app

    Step 01

    We will open a Run window

    On the keybord press

    Windoes Key + R
    

    wait

    Step 02

    We will open a cmd Window

    On the Run window text-Input write

    cmd
    

    on the Keybord press

    Enter
    

    Step 03

    We will make a directory and make it the working directory for our cmd

    On the CMD Window write

    mkdir D:\Experiments\E.IDser.NativeScript
    
    cd /d D:\Experiments\E.IDser.NativeScript
    

    Step 04

    We will make a clone the sample project

    On the CMD Window write

    git clone https://github.com/Elrashid/nativescript-client-and-identity-server-sample.git
    
    cd nativescript-client-and-identity-server-sample
    

    Step 05

    Now will run the apps

    On the CMD Window write

    Start.bat
    

    Step 06

    how to use

    enter image description here enter image description here enter image description here

    enter image description here enter image description here enter image description here

    why

    1    app
                  +---+
                      |
         identity     |
    2    server       |
                      |
                      |
                      |
    3    google       +-+   user
                      |     intractiom
                      |
                      |       your
         identity     |       app
    4    server       | <---+ stop
                  +---+       here
    
    5     app     +---+
                      |
                      |
                      |
         identity     +--+  background
    6    server       |
                      |
                      |
    7     app         |
                   +--+
    

    see register a custom URL scheme for Android

    <data 
    android:path="/home"
    android:scheme="com.mysite.nativeapp
                .12365789785256-buv2dwer7
                jjjjv5fckasdftn367psbrlb"
    />
    

    also you can try

     tns debug android
    

    Erorr This site cannot be reached

    communication between Identity Server and Native-Script

    • run

      nativescript-client-and-identity-server-sample/Start.bat
      
    • do not run run

      "nativescript-client-and-identity-server-sample/identity-server/Start.bat"
      "nativescript-client-and-identity-server-sample/nativescript-client/Start.bat"
      
    • native script app should run in in android emulator

      enter image description here

    • identity server should be run in local machine at port 5010

    • check in your windows browser you can open

      http://localhost:5010
      
    • if yes

    • check in your **android emulator ** browser you can open

      http://10.0.2.2:5010
      
    • what is 10.0.2.2 ?

      special alias to your android emulator host loopback interface

    • can i change where my host 10.0.2.2 ?

      open nativescript-client\app\my-oauth-provider.ts

          public authority = "http://10.0.2.2:5010";
          public tokenEndpointBase = "http://10.0.2.2:5010";
          public cookieDomains = ["10.0.2.2:5010"];
      
    • change http://10.0.2.2:5010 to your web address