native-ios-sdk icon indicating copy to clipboard operation
native-ios-sdk copied to clipboard

login(withAccessToken:) throwing unauthorised error for passing nil to refreshToken and expiresIn optional parameters.

Open rakshithn96 opened this issue 1 year ago • 14 comments

Our backend uses the JWT Grant because we perform a single login for all users in our DocuSign integration. Since we are not using OAuth, a refresh token is not available. In version 3.1.0, new parameters refreshToken and expiresIn were added. When I pass nil to these parameters, the DocuSign framework returns an unauthorized error. Are these parameters mandatory, or can someone provide more information on how to resolve this issue?

rakshithn96 avatar Jul 09 '24 17:07 rakshithn96

Hi @rakshithn96 :

We are looking into this and will add an update. Meanwhile, putting this as a reference, the updated sample app which has the login-flow details are present here: https://github.com/docusign/sample-app-tgk-financial-ios/

Details on the refreshToken & expiresIn usage is linked here: https://developers.docusign.com/docs/mobile-sdks/ios-sdk/how-to/log-in/

Thanks.

ashokds avatar Jul 09 '24 22:07 ashokds

Hi @rakshithn96 :

Are you migrating your app from an old DocuSignSDK version to a new one?

Could you please share the current code snippet for the SDK call that results in the unauthorized error and the network log. It would be helpful to quickly resolve it.

Thanks.

ashokds avatar Jul 11 '24 22:07 ashokds

Hi @ashokds

I'm trying to upgrade the Docusign from 3.0.3 to 3.2.0. The Xcode version is 15.2. I am using the default login function to login to the DocuSign framework.

About the network calls. Like 3.0.3 the 3.2.0 version does not initiate any network calls.

Login is done as below with 3.2.0 with 2 new parameters refreshToken and expiresIn:

      DSMManager.login(withAccessToken: accessToken, accountId: accountId, userId: userId, userName: userName, email: email, host: hostUrl, integratorKey: integratorKey, refreshToken: nil, expiresIn: nil) { [weak self] _, error in
            if let error = error {
                dLog(logType: .docusign, "Docusign login error: \(error)")
                return
            }
        }

rakshithn96 avatar Jul 15 '24 11:07 rakshithn96

Hi @rakshithn96 :

Would it be possible to post the steps you use to get the AccessToken and network logs around it. We could schedule a debug session with your team - could you please send the details and your availability to Mobile Feedback <mobilefeedback [at] docusign.com> (replace [at] with @) and we'll follow up.

Thanks for your patience and help so far,

ashokds avatar Jul 23 '24 20:07 ashokds

We have also got the same issue while We are doing migration from the 2.12.0 to 3.2.0. and We are using

https://auth.emea-1.jumio.ai/oauth2/token and https://account.emea-1.jumio.ai/api/v1/accounts for getting the token via Docusing Rest aPI.

@ashokds @mmohareb Please suggest us how should we proceed

depushpendra avatar Aug 07 '24 12:08 depushpendra

can you confirm you followed this step 2 in the project setup? https://developers.docusign.com/docs/mobile-sdks/ios-sdk/how-to/log-in/ image

mmohareb avatar Aug 07 '24 17:08 mmohareb

@mmohareb , sure we will add this but where can we get refreshToken , is it stored in SDK or we get it in response of OAuth Token

bhagwat8024 avatar Aug 08 '24 06:08 bhagwat8024

Refresh token can be nil in your case since you are not using oAuth.

mmohareb avatar Aug 08 '24 06:08 mmohareb

@mmohareb do we need to add step 2 in Info.plist even when we are JWTTOken?

depushpendra avatar Aug 08 '24 06:08 depushpendra

Yes this step is mandatory regardless of the way you authenticate the SDK

mmohareb avatar Aug 08 '24 06:08 mmohareb

Thanks we will add it but could be possible cause of login(withAccessToken:) throwing unauthorised error for passing nil to refreshToken and expiresIn optional parameters ? Even if we use valid token

depushpendra avatar Aug 08 '24 06:08 depushpendra

Missing this step will surely cause the unauthorized issue as without this the SDK can’t access the keychain to store the authentication key(either oauth or jwt grant)

The refresh token is an optional parameter that would allow the SDK to refresh the access token after expiry if oauth is being used. So sending nil should not cause this issue.

mmohareb avatar Aug 08 '24 06:08 mmohareb

Thanks @mmohareb We will try by adding above step and check. I will let you know incase I will need anymore help.

👍👍👍

depushpendra avatar Aug 08 '24 06:08 depushpendra

@mmohareb After updating the info.plist, there are no callbacks (success or error) received during the login process using DSMManager.login. Here is the code snippet we use for login

DSMManager.login(
    withAccessToken: token,
    accountId: config.accountId,
    userId: config.userId,
    userName: config.userName,
    email: config.email,
    host: url,
    integratorKey: config.integrationKey,
    refreshToken: nil,
    expiresIn: nil
) { (account, error) in
    DispatchQueue.main.async {
        if let account = account, error == nil {
            completion(.success(account))
        } else if let error = error {
            completion(.failure(error))
        } else {
            completion(.failure(
                ConnectError.appLevelError(
                    error: ErrorMetadata(errorMessage: "DocuSign login failed",
                                         response: "DocuSign login failed, accessToken: " + token),
                    isLocal: true
                ))
            )
        }
    }
}

bhagwat8024 avatar Aug 08 '24 10:08 bhagwat8024

@bhagwat8024 is it possible to share a complete log from your app on [email protected]? if needed we can setup a working session to support you with your integration

mmohareb avatar Aug 08 '24 16:08 mmohareb

@mmohareb Yes, we can have a working session tomorrow to support the integration. Please let me know your availability for the session.

bhagwat8024 avatar Aug 12 '24 11:08 bhagwat8024

@bhagwat8024 please reach out to the email mentioned above to arrange this session.

mmohareb avatar Aug 12 '24 16:08 mmohareb

Thanks @bhagwat8024 and @depushpendra To fix the issue with no callbacks for login method, you need to pass the expiresIn parameter for the lifetime of the token. The refresh token can stay nil and should not cause issues. Let me know if this works for your scenario, and we will work on updating the docs and handling this better with our next release.

mmohareb avatar Aug 14 '24 17:08 mmohareb

@rakshithn96 please update us if this issue is still happening for you too?

mmohareb avatar Aug 14 '24 17:08 mmohareb