Code Monkey home page Code Monkey logo

flutteroauth's Introduction

Flutter OAuth

A Flutter OAuth package for performing user authentication for your apps.

I've tested this with a small collection of APIs (Buffer, Strava, Unsplash and GitHub). If there is an issue with an API you are trying to work with, please file an issue :)

Authorizing an application

Performing authorization for an API is straight forward using this library. In most cases you will just be able to use the following approach:

final OAuth flutterOAuth = new FlutterOAuth(new Config(
    "https://unsplash.com/oauth/authorize",
    "https://unsplash.com/oauth/token",
    "YOUR_CLIENT_ID",
    "YOUR_CLIENT_SECRET",
    "http://localhost:8080",
    "code"));

This allows you to pass in an Authorization URL, Token request URL, Client ID, Client Secret, Redirect URL and the response type. This should satisfy most requests, but if not then you can pass in other optional parameters for:

  • contentType - This allows you to change the content type for the request. For example, for Spotify API authorization you need to use "application/x-www-form-urlencoded"
final OAuth flutterOAuth = new FlutterOAuth(new Config(
    ...,
    contentType: "application/x-www-form-urlencoded"));
  • parameters - Add your own parameters that this library may not support out-of-the-box. For example, with the GitHub API you can send a state string and scopes to gain authorization for
Map<String, String> customParameters = {"state": "SOME_RANDOM_SECURE_STRING", "scope": "public_repo"};

final OAuth flutterOAuth = new FlutterOAuth(new Config(
    ...,
    parameters: customParameters));
  • headers - Some APIs require you to send custom headers, such as an Authorization Header. Use this parameter if you require this
Map<String, String> headers = {"Authorization": "Basic SOME_BASE_64_STRING"};

final OAuth flutterOAuth = new FlutterOAuth(new Config(
    ...,
    headers: headers));

Then once you have an OAuth instance, you can simply call the performAuthorization() method like so to retrieve a Token instance:

Token token = await flutterOAuth.performAuthorization();
String accessToken = token.accessToken;

Installing

Add the following you your pubspec.yaml dependancies:

dependencies:
  flutter_oauth: "^0.0.1"

Thanks to

Kevin Seqaud for his awesome blog post on Flutter OAuth https://medium.com/@segaud.kevin/facebook-oauth-login-flow-with-flutter-9adb717c9f2e

The author, Hadrien Lejard, behind the:

The Gitter-Dart repo, where a lot of this library was influenced

and the Flutter Webview plugin, which this library uses

flutteroauth's People

Contributors

chances avatar hitherejoe avatar takahirom avatar tristanwilson111 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutteroauth's Issues

Error message when adding flutter_oauth to dependencies

Every time that I enable flutter_oauth: "^0.0.1" in the dependencies in my pubspec.yaml I get the following message:

Error detected in pubspec.yaml:
#/properties/flutter: type: wanted [object] got null

The application runs and builds, though.

get state value

After succussfully get auth code how I can get state value for sending own server.

var result = await appAuth.authorize( AuthorizationTokenRequest( '$clientId', '$redirectUri', discoveryUrl: finalUrl, serviceConfiguration: AuthorizationServiceConfiguration(finalUrl, ""), scopes: ['profile'], ), );

Cann't use it on Dart 2.5.0

Running "flutter pub get" in smart_parking_flutter... The current Dart SDK version is 2.5.0.

Because smart_parking_flutter depends on flutter_oauth any which requires SDK version >=1.8.0 <2.0.0, version solving failed.
pub get failed (1)
Process finished with exit code 1

iOS behaviour

Thanks for this plugin. Tested the example on Android with Strava and works out of the box. Just checking if additional configuration is needed for this to work on iOS - specifically to refocus the flutter app. At moment, after entering facebook credentials I get stuck on a facebook loading screen.

Cheers.

Project Maintenance

Hi, this project currently it's not being maintained, right?

What would be the best option for the same? Are there any recommended forks?

Configurable local callback server

Hi,

API providers are sometimes very restrictive about redirect uris.
Please provide a way to customize the server parameters so that it can match every callback uri.
Especially the port number.

Doesn't work with Google

I'm trying to authenticate against a YouTube Google account. I get a 403 in the webview that says:

Error: disallowed_useragent

This user-agent is not permitted to make an OAuth authorization request to Google as it is classified as an embedded user-agent (also known as a web-view). Per our policy, only browsers are permitted to make authorization requests to Google...

Is there a workaround for this with this library? Any reason this library doesn't just open a browser?

type 'Future<dynamic>' is not a subtype of type 'Future<Null>'

I tried to create a very basic example.
I just created a method like this and called it:
`Future _performOAuthLogin(String client_id, String client_secret) {
final OAuth flutterOAuth = new FlutterOAuth(new Config(
"https://localhost:8888/oauth/authorize",
"https://localhost:8888/oauth/token",
client_id,
client_secret,
"http://localhost:8080",
"code"));

return flutterOAuth.performAuthorization();

}`

This code snippit leads to the following exception:
[VERBOSE-2:dart_error.cc(16)] Unhandled exception: type 'Future<dynamic>' is not a subtype of type 'Future<Null>' #0 FlutterWebviewPlugin.close (package:flutter_webview_plugin/flutter_webview_plugin.dart:73:36) #1 FlutterOAuth.requestCode (package:flutter_oauth/lib/flutter_auth.dart:26:21) <asynchronous suspension> #2 OAuth.performAuthorization (package:flutter_oauth/lib/oauth.dart:49:31) <asynchronous suspension>

Am i doing something wrong?

Does not work with current Flutter version (not compatible with Dart2)

[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
type 'Future' is not a subtype of type 'Future'
#0 FlutterWebviewPlugin.close (package:flutter_webview_plugin/flutter_webview_plugin.dart:73:36)
#1 FlutterOAuth.requestCode (package:flutter_oauth/lib/flutter_auth.dart:26:21)

#2 OAuth.performAuthorization (package:flutter_oauth/lib/oauth.dart:49:31)

Doesnt work with latest flutter

Error message is:

The current Dart SDK version is 2.1.0-dev.5.0.flutter-a2eb050044.

Because flutter_app_delete depends on flutter_oauth any which requires SDK version >=1.8.0 <2.0.0, version solving failed.

Need to upgrade flutter webview plugin dependency

I'm getting errors related to a return type of Future within the flutter_webview_plugin. I checked that repo and those response types have been changed to a generic Future without the . I think you need to update the dependency number to get the latest flutter_webview_plugin.

Fitbit Api Oauth Issue

I am trying to connect to fitbit oauth, here is my code:

Map<String, String> customParameters = {"scope": "activity"};
final OAuth flutterOAuth = new FlutterOAuth(new Config(
"https://www.fitbit.com/oauth2/authorize",
"https://api.fitbit.com/oauth2/token",
"######",
"################",
"http://localhost:8080",
"code",
parameters:customParameters,
contentType: "application/x-www-form-urlencoded"));

But i keep getting a null return after I logged in and allowed access to app.

Error:
I/flutter ( 6554): null
E/flutter ( 6554): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 6554): 'package:flutter/src/widgets/text.dart': Failed assertion: line 212 pos 15: 'data != null': is not true.
E/flutter ( 6554): #0 _AssertionError._doThrowNew (dart:core-patch/dart:core/errors_patch.dart:37)
E/flutter ( 6554): #1 _AssertionError._throwNew (dart:core-patch/dart:core/errors_patch.dart:33)
E/flutter ( 6554): #2 new Text (package:flutter/src/widgets/text.dart:212:15)
E/flutter ( 6554): #3 MainState.authorise (/data/user/0/co.joebirch.tide/cache/exampleFJXSCW/example/lib/main.dart:71:20)
E/flutter ( 6554):
E/flutter ( 6554): #4 MainState.build. (/data/user/0/co.joebirch.tide/cache/exampleFJXSCW/example/lib/main.dart:47:36)
E/flutter ( 6554): #5 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:478:14)
E/flutter ( 6554): #6 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:530:30)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.