· hobby developer

3rd party (Strava) Oauth Login in Flutterflow

Custom Code

Hi used to allow users to login using strava or other 3rd parties - do help please!

I am trying to use https://pub.dev/packages/strava_client and want to use the native app strava authorization depending on the device (ios/android) used by the user. That is, if user is on ios, then the ios app should be opened and similarly for android.

What have you tried so far?

I have built a custom action in FF which is triggered on a button click. Apart from the library examples am trying to use gpt to help me build the code, that doesn't seem to work very well. Could you please help me understand the mistakes i have made and how to get it working?

Attached is the error screenshot (please note i do not use firestore but there seem to some browser console errors related to that too!).

Error text - Error: Unsupported operation: Platform._operatingSystem

Here is the code i am currently using in my custom action -

// Automatic FlutterFlow imports
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'dart:async';
import 'package:strava_client/strava_client.dart';

Future<void> stravaLogin() async {
  // Initialize the StravaClient
  final stravaClient = StravaClient(
      secret: 'bf0e6a58f152fe00d3bc7854a20c47fb6e10ca82', clientId: '37730');
  final exampleAuth = ExampleAuthentication(stravaClient);
  debugPrint('try strava login next');

  try {
    final token = await exampleAuth.testAuthentication(
      [
        AuthenticationScope.profile_read_all,
        AuthenticationScope.read_all,
        AuthenticationScope.activity_read_all
      ],
      "stravaflutter://redirect",
    );

    // Handle the successful authentication response
    debugPrint('Access Token: ${token.accessToken}');
  } catch (e) {
    // Handle the error
    debugPrint('Error: $e');
    // showSnackbar(Text("Incremented"), duration: Duration(milliseconds: 300)));
    // return 'there was an error';
  }
}

FutureOr<Null> showErrorMessage(dynamic error, dynamic stackTrace) {
//   if (error is Fault) {
//     showDialog(
//         context: context,
//         builder: (context) {
//           return AlertDialog(
//             title: Text("Did Receive Fault"),
//             content: Text(
//                 "Message: ${error.message}\n-----------------\nErrors:\n${(error.errors ?? []).map((e) => "Code: ${e.code}\nResource: ${e.resource}\nField: ${e.field}\n").toList().join("\n----------\n")}"),
//           );
//         });
//   }
}

class ExampleAuthentication {
  final StravaClient stravaClient;
  ExampleAuthentication(this.stravaClient);

  Future<TokenResponse> testAuthentication(
      List<AuthenticationScope> scopes, String redirectUrl) {
    return stravaClient.authentication.authenticate(
        scopes: scopes,
        redirectUrl: redirectUrl,
        forceShowingApproval: false,
        callbackUrlScheme: "stravaflutter",
        preferEphemeral: true);
  }

  Future<void> testDeauthorize() {
    return stravaClient.authentication.deAuthorize();
  }
}

Did you check FlutterFlow's Documentation for this topic?
No
2
4 replies