0

I am working on a Fyne app that is to be compiled and installed as an Android app.

The app allows a user to authenticate using oauth2. The authentication server returns the auth code back to the app in the url string as parameter values. I am able to make a deep link and through the deep link open my fyne app, but have no idea how to access the data string of the intent in order to parse the parameter values.

Extensive research on Google only shows solutions in Kotlin/Java with no mention of anyone achieving this in Golang or a Fyne project.

The activity part of the AndroidManifest.xml of the project is as follows

<activity
            android:label="myapp"
            android:name="org.golang.app.GoNativeActivity"
            android:configChanges="0xa0">
            <meta-data
                android:name="android.app.lib_name"
                android:value="myapp" />
            <intent-filter>
                <action
                    android:name="android.intent.action.MAIN" />
                <category
                    android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter 
                android:label="@string/oauth2_deep_link">
                <!-- below for Deep Linking -->
                <action 
                    android:name="android.intent.action.VIEW" />
                <!-- allows your app to respond to implicit intents. Without this, the activity can be started only if the intent specifies your app component name.-->
                <category 
                    android:name="android.intent.category.DEFAULT" />
                <!-- BROWSABLE required for intent-filter to be accessible from browser-->
                <category 
                    android:name="android.intent.category.BROWSABLE" />
                <!-- Accepts URIs that begin with "myapp://oauth2/code” -->
                <data 
                    android:scheme="myapp"
                    android:host="oauth2" />
                
            </intent-filter>
        </activity>

I am hoping the return the auth code back to the app using the url "myapp://oauth2/?code=kalksdnfaldsfn

Don't know much about Kotlin, but I think this can be achieved in Kotlin by using something like the following function.

fun Intent.getData(key: String): String {
    return extras?.getString(key) ?: "intent is null"
}

Does Golang have a library to achieve this?

yebowhatsay
  • 182
  • 1
  • 7
  • Everything stats with the oauth2 grant type, but for the code grant types (response_type=code) you will need some type of local server listening on that callback "myapp://oauth2..." url for the oauth server to make the get request with the token(s) google call this "Loopback IP address " https://developers.google.com/identity/protocols/oauth2/native-app. I am not sure what you mean by deep link but I think it would help if you could provide specifics as to your grant type see https://datatracker.ietf.org/doc/html/rfc6749#section-1.3 – Nigel Savage Sep 16 '21 at 18:38
  • @NigelSavage Thanks for the comment. The question isn't about oauth2. I have mentioned oauth2 here just as a use case. It is about receiving url params with deep-linking on an android golang/fyne app. [Deep-linking](https://www.adjust.com/glossary/deep-linking/) – yebowhatsay Sep 17 '21 at 02:46
  • I guess my comment was directed at this statement "I am hoping the return the auth code back to the app using the url "myapp://oauth2/?code=kalksdnfaldsfn". – Nigel Savage Sep 17 '21 at 09:06
  • Yes, I can configure the oauth2 server to return the code back using a custom deep-link url. So, factually correct. But, agree it could make the question confusing. Thanks. – yebowhatsay Sep 17 '21 at 10:33
  • sorry, I was thinking that the "data string of the intent" was related to the parameters in that oauth callback url, so that would be the place to start building the solution – Nigel Savage Sep 17 '21 at 10:46
  • I think you will need to use an event to get this into your data string into your go code, events have the shape Events() <-chan interface{} so they can be anything, perhaps you may need a custom GoNativeActivity to pass the intent data from the system as an event. This question has a GoNativeService.java that could possibly give you some ideas, https://stackoverflow.com/questions/49461141/how-to-run-a-simple-go-script-as-an-android-service, you could also check what events you have coming in, perhaps its there already? – Nigel Savage Sep 17 '21 at 11:54
  • 1
    I don’t think there is a standard way to do this (yet). The only launch parameters would be those from the initial launch in the `flags.Args`, which is not where this is passed. – andy.xyz Sep 17 '21 at 20:25
  • 1
    Did you consider running the http listener for the callback inside your Go code and accessing the code directly instead of passing it back through intent? That way the value could be read through standard HTTP queries and you could then use the deep link to simply return the app to the foreground? – andy.xyz Sep 17 '21 at 20:27
  • Thanks for clarifying that, @andy.xyz. Was about time you came to the party :) I also realised this method was probably insecure so have gone back to using https. And yes, can still use deep link to bring up the app once the code is received back. – yebowhatsay Sep 18 '21 at 00:36

0 Answers0