sdk-android icon indicating copy to clipboard operation
sdk-android copied to clipboard

How to add user login?

Open Catzoy opened this issue 6 years ago • 12 comments

In step 2 of "Getting Started" our app must add a callback activity for user OAuth login with some "redirect URL", yet it is unclear what redirect URL must do and who provides such URL. Please explain how to add user authorization to the app.

Catzoy avatar Jul 13 '20 11:07 Catzoy

Hi @Catzoy

Sorry for the lack if details, there is still a work in progress regarding the integration process and documentation.

In the https://developer.izettle.com/ after you create a Payments Android SDK credential you will be prompted to add the redirect URI. In the app, after user finish an authentication (which happen in a browser) we still redirect to this URI and the sdk will handle the result.

We suggest to not use https since it's really specific for iZettle login for your app and we would like to not have deep link conflict with other apps, in the same way when you share a photo and you are prompted to choose which app will handle it.

If you choose this redirect URI:

Screenshot 2020-07-13 at 15 29 33

Then in our sample you must fill the iZettleSDK.gradle with this:

Screenshot 2020-07-13 at 15 39 23

Please, let us know if you have any problem.

fabriciovergara avatar Jul 13 '20 13:07 fabriciovergara

Hi @fabriciovergara

Thank you for quick response!

Issue was that we didn't add any OAuth Redirect URI in the https://developer.izettle.com/ for our app and that's why SDK always returned "redirect_url contains not allowed URI" for anything we tried.

Closing issue as resolved.

Catzoy avatar Jul 14 '20 08:07 Catzoy

Hi,

@fabriciovergara you said the SDK "will handle the result" when redirected in redirect URL. In my app, after login in the browser, I see the access_token (displayed from my redirect_uri), and that's all, nothing else is happening. How do we return to the application with the access_token taken into account ?

Thanks

Rémi

remitettiravou avatar Aug 03 '20 13:08 remitettiravou

@remitettiravou

After the login, the browser will be redirect to the deep-link registered in your app manifest:

<activity 
    android:name="com.izettle.android.auth.OAuthActivity" 
    android:launchMode="singleTask"
    android:taskAffinity="@string/oauth_activity_task_affinity"> 
    <intent-filter> 

        <!-- Deep link data -->
        <data 
            android:host="izettlelogin"  
            android:scheme="izettlesample />
       

       <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
    </intent-filter>
</activity>

Please, check if the values are correct and the same as declared in the developer portal.

fabriciovergara avatar Aug 03 '20 13:08 fabriciovergara

I used to have https scheme. Now with "app" scheme and my Activity for host, it is working. Thanks.

remitettiravou avatar Aug 03 '20 14:08 remitettiravou

I'm getting the message:

Invalid protocol, can not start with "izettle" or be one of http:// or file://.

When trying to put izettlesample://izettlelogin in the OAuth Redirect URIs list.

Has the correct redirect URI changed by now?

Olmectron avatar Oct 03 '20 21:10 Olmectron

@Olmectron please not use in the scheme the words http or izettle

atsneves avatar Dec 23 '20 04:12 atsneves

Hi @Catzoy

Sorry for the lack if details, there is still a work in progress regarding the integration process and documentation.

In the https://developer.izettle.com/ after you create a Payments Android SDK credential you will be prompted to add the redirect URI. In the app, after user finish an authentication (which happen in a browser) we still redirect to this URI and the sdk will handle the result.

We suggest to not use https since it's really specific for iZettle login for your app and we would like to not have deep link conflict with other apps, in the same way when you share a photo and you are prompted to choose which app will handle it.

If you choose this redirect URI:

Screenshot 2020-07-13 at 15 29 33

Then in our sample you must fill the iZettleSDK.gradle with this:

Screenshot 2020-07-13 at 15 39 23

Please, let us know if you have any problem.

I have also followed same and login is working redirecting to app but never able to see access token and refresh token in onActivityResult(). but what about access token as mentioned in documentation??

But i can see the log like 2023-01-03 11:42:51.144 25633-25700/com.pospal.pospal I/TokenRepositoryImpl: [{userId=3f329550-70fb-11e5-a847-bda5b59ed83f, tokens=OAuthTokens(accessToken=eytg, refreshToken=IZ89, expirationDate=Tue Jan 03 13:42:50 GMT+05:30 2023, scopes=[READ:PAYMENT, READ:USERINFO, WRITE:PAYMENT])}] at com.izettle.android.auth.log.StackTraceKt.withStackTrace(SourceFile:1) at com.izettle.android.auth.TokenRepositoryImpl$applyStoreTokensToTransaction$1.invoke(SourceFile:3) at com.izettle.android.auth.TokenRepositoryImpl$applyStoreTokensToTransaction$1.invoke(SourceFile:1) at com.izettle.android.auth.storage.Transaction.commit(SourceFile:27) at com.izettle.android.auth.tasks.OAuthLoginTask.finalizeTask(SourceFile:10) at com.izettle.android.auth.tasks.OAuthAuthTask$resume$1.invoke(SourceFile:15) at com.izettle.android.auth.tasks.OAuthAuthTask$resume$1.invoke(SourceFile:1) at com.izettle.android.auth.executor.ExecutorImpl.schedule$lambda-3(SourceFile:2) at com.izettle.android.auth.executor.ExecutorImpl.$r8$lambda$ApSXqycmJTVshYvryZVW9t0bXko(Unknown Source:0) at com.izettle.android.auth.executor.ExecutorImpl$$ExternalSyntheticLambda0.run(Unknown Source:8) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:233) at android.os.Looper.loop(Looper.java:334) at android.os.HandlerThread.run(HandlerThread.java:67) 2023-01-03 11:42:51.216 25633-25633/com.pospal.pospal I/XDR::VRT: sc is not valid!

crashfiredeep avatar Jan 03 '23 06:01 crashfiredeep

@crashfiredeep Not sure I understand your question correctly. But you don't get the AccessToken or RefreshToken in the onActivityResult(). Instead, you should observe the authentication state. Please see this.

Here is the example code in Example project. (https://github.com/iZettle/sdk-android/blob/master/Examples/Example-Kotlin/app/src/main/java/com/izettle/payments/android/kotlin_example/MainActivity.kt#L33)

CheZhongSdk avatar Jan 03 '23 15:01 CheZhongSdk

@crashfiredeep Not sure I understand your question correctly. But you don't get the AccessToken or RefreshToken in the onActivityResult(). Instead, you should observe the authentication state. Please see this.

Here is the example code in Example project. (https://github.com/iZettle/sdk-android/blob/master/Examples/Example-Kotlin/app/src/main/java/com/izettle/payments/android/kotlin_example/MainActivity.kt#L33)

that is already implemented but if logged in states of login is also coming false, and what if I need to access payment flow using token. in these methods there is no way to get token and refresh token. My app is need to login every time for payment, so I want to store the token and process further based on this token, so that user only need to login once.

crashfiredeep avatar Jan 04 '23 16:01 crashfiredeep

Hi @crashfiredeep, the SDK doesn't expose the tokens and we have no plan of doing so. Today there are two ways of authenticating the SDK.

  • The SDK handles everything, you just tell it to log in.
  • You handle authentication and provide a refresh token that the SDK can use to fetch access tokens when needed. When doing a refund a UI will be triggered to verify the credentials.

Both of the above methods will keep the user logged in as long as the tokens are valid. So if you don't explicitly log out the user you should not be prompted to log in on every payment. The tokens are valid for quite some time.

As a side note. We are also working on a third way where the integrator is in full control over the tokens and the SDK will only ask for tokens when needed leaving the integrator in full control. But we don't have a release date for this yet.

bobzettle avatar Jan 09 '23 13:01 bobzettle

I am attempting to implement this but I am still stuck with Parameter redirect_url contains an URI that is not allowed

ext.iZettleSDK.redirectUrlScheme = "com.pospal.epos" ext.iZettleSDK.redirectUrlHost = "oauth"

and the redirect url in the developer OAuth Redirect URIs is set to the same com.pospal.epos://oauth

hennaboy avatar Aug 03 '25 19:08 hennaboy