1

I am trying to connect my iOS app to a Keycloak server for authentication purposes and have decided to use AeroGear library to do it. I did the initial setup as described in the Readme and configured everything Server side. The code I am using to initiate login is this:

    let keycloakConfig = KeycloakConfig(
        clientId: "testclient",
        host: "http://localhost:8080",
        realm: "testrealm",
        isOpenIDConnect: true
    )
    let oauth2Module = AccountManager.addKeycloakAccount(config: keycloakConfig)
    //let oauth2Module = KeycloakOAuth2Module(config: keycloakConfig, session: UntrustedMemoryOAuth2Session(accountId: "ACCOUNT_FOR_CLIENTID_\(keycloakConfig.clientId)"))
    let http = Http()
    http.authzModule = oauth2Module
    oauth2Module.login {(accessToken: AnyObject?, claims: OpenIdClaim?, error: NSError?) in
        print("login successful")
        // some other stuff happens here
    }

The app takes me to login screen of Keycloak where I put in the user info and it seems like the login works as I get redirected back to my app. But for some reason nothing that should happen doesn't happen afterwards - for example the print to console. When I tried it in a different app it worked so it must be ok but I don't know how to debug this. The session on Keycloak seems alright so I have no idea what could cause this... I would appreciate some advice as I am very good at this.

dj-neza
  • 198
  • 1
  • 11
  • Have you tried to run/take a look at or cookbook example app? https://github.com/aerogear/aerogear-ios-cookbook/tree/master/SharedShoot https://github.com/aerogear/aerogear-backend-cookbook/tree/master/Shoot – Daniel Passos Feb 11 '18 at 13:38
  • @Passos this is what I started with and in the Shoot app it works, then I put the same code in my app and nothing happens.. I configured everything like it's described (added the right URI schemes to Keycloak) and everything happens like it should except for the code inside the login closure... – dj-neza Feb 12 '18 at 08:09
  • UPDATE: is it possible it's a closure problem? It seems to work as an @IBAction function? If so what would be the right workaround as I don't want to use it as an action.. – dj-neza Feb 12 '18 at 12:19
  • That is really weird, you should not be able to use it only as an @IBAction – Daniel Passos Feb 17 '18 at 19:48
  • @Passos I know, right? And yet this is happening.. But anyway I did this via IBAction and got it to work so I guess it's a solution for now. – dj-neza Feb 20 '18 at 12:51
  • Hello @dj-neza , i need your help for keyclock , can you please help me in this – Anita Nagori Mar 05 '20 at 06:53

0 Answers0