mercedes-benz / MBSDK-Mobile-iOS

Mercedes-Benz Mobile SDK - Mobile module for iOS
MIT License
32 stars 14 forks source link

BYOCAR with MBSDK #5

Open UPetersen opened 3 years ago

UPetersen commented 3 years ago

Hi, I managed to get access to my own car via the web API, which is great, but limited. Is it also possible, to access my own car via the MBSDK? If so, what would be the recommended settings in app delegate (.mock or .prod, .keycloak to .ciam)? Are all services accessible as with the production environment or simulator? Any other hints? Regards @UPetersen

Leon16 commented 3 years ago

I have the similar question. I tried to use MBSDK-Mobile-iOS and run the sample code using the following settings:

    let clientId = "30b29cad-52cd-482a-b84e-820a646096c6" (from the console of my account)
    let config = MBMobileSDKConfiguration(applicationIdentifier: "example",
                                          authenticationConfigs: [
                                            ROPCAuthenticationConfig(clientId: clientId, type: .keycloak),
                                            ROPCAuthenticationConfig(clientId: clientId, type: .ciam)
                                          ],
                                          endpoint: MBMobileSDKEndpoint(region: .ece,
                                                                        stage: .prod),
                                          preferredAuthMethod: .keycloak)
    MobileSDK.setup(configuration: config)
    MobileSDK.usePinProvider(pinProvider: ExamplePinProvider())

However it always returns error with description:

description = "unauthorized_client -> INVALID_CREDENTIALS: Invalid client credentials"

I used my own Mercedes Me account as user name and the OTP from the email. I could log into my account via web site but not sure I got the error when using MBSDK-Mobile.

Leon16 commented 3 years ago

Further investigation result: I tried to use

let clientId = "app"

and also set the stage as .mock at the call below:

MBMobileSDKEndpoint(region: .ece, stage: .mock) 

It looks that the client Id check is skipped. However it comes back the error in the following call:

loginProvider.login(username: username, credential: self.credential(for: loginProvider.type, pin: pin, nonce: nonce)) { [weak self] result in

        switch result {
        case .success:
            LOG.V("Succcessfully logged in user; Fetching user data...")
            self?.fetchUser(completion: completion)

        case .failure(let error):
            LOG.E("Login request did fail with error: \(error)")
            completion(.failure(error))
        }
    }

and the result description is .loginDidFailWithInvalidPin. It looks like the authentication service returns with error in matching the OTP pin with the user account (although I could log in with the same OTP from the web)