Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,54 @@ group 'com.maru.twitter_login'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath "com.android.tools.build:gradle:4.1.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.4' // Update Gradle version
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

rootProject.allprojects {
repositories {
google()
mavenLocal()
}
repositories {
google()
mavenLocal()
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 31
compileSdkVersion 34
ndkVersion "26.1.10909125"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}
kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
minSdkVersion 16
}
defaultConfig {
minSdkVersion 21
}

dependencies {
implementation "androidx.browser:browser:1.3.0"
}
dependencies {
implementation "androidx.browser:browser:1.3.0"
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
4 changes: 3 additions & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true

org.gradle.jvmargs=--add-opens java.base/java.io=ALL-UNNAMED

4 changes: 3 additions & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion flutter.compileSdkVersion

ndkVersion "26.1.10909125"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand All @@ -43,7 +45,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.maru.twitter_login_example"
minSdkVersion flutter.minSdkVersion
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
5 changes: 4 additions & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
org.gradle.jvmargs=-Xmx1536M

android.useAndroidX=true
android.enableJetifier=true

org.gradle.jvmargs=--add-opens java.base/java.io=ALL-UNNAMED

2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
8 changes: 6 additions & 2 deletions lib/entity/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ class User {
apiKey: apiKey,
oauthToken: accessToken,
);

final params = await httpGet(
ACCOUNT_VERIFY_URI,
// '$USER_LOCKUP_URI/me',
authHeader: authParams,
apiKey: apiKey,
apiSecretKey: apiSecretKey,
tokenSecret: accessTokenSecret,
);

return User(params);
} on Exception {
rethrow;
Expand All @@ -98,13 +101,14 @@ class User {
String userId,
) async {
try {
final token = await Oauth2.getBearerToken(apiKey: apiKey, apiSecretKey: apiSecretKey);
final token = await Oauth2.getBearerToken(apiKey: accessToken, apiSecretKey: accessTokenSecret);
if (token?.isEmpty ?? true) {
throw Exception();
}


final params = await httpGetFromBearerToken(
'$USER_LOCKUP_URI/$userId',
'$USER_LOCKUP_URI/ids:$userId,',
query: {'user.fields': 'id,name,username,profile_image_url'},
bearerToken: token!,
);
Expand Down
1 change: 1 addition & 0 deletions lib/schemes/access_token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AccessToken {
if (params == null) {
throw Exception();
}

return AccessToken(params);
}
}
2 changes: 1 addition & 1 deletion lib/src/oauth_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:twitter_login/src/utils.dart';

// ignore: avoid_classes_with_only_static_members
class Oauth2 {
/// get applicatoin Bearer Token.
/// get application Bearer Token.
///
/// https://developer.twitter.com/en/docs/authentication/oauth-2-0/application-only
static Future<String?> getBearerToken({
Expand Down
2 changes: 1 addition & 1 deletion lib/src/twitter_login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ class TwitterLogin {
if (queries['denied'] != null) {
throw const CanceledByUserException();
}

final token = await AccessToken.getAccessToken(
apiKey,
apiSecretKey,
Expand Down Expand Up @@ -244,6 +243,7 @@ class TwitterLogin {
}

final queries = Uri.splitQueryString(Uri.parse(resultURI!).query);

if (queries['error'] != null) {
throw Exception('Error Response: ${queries['error']}');
}
Expand Down
3 changes: 3 additions & 0 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,16 @@ Future<Map<String, dynamic>> httpGetFromBearerToken(
}) async {
try {
final _httpClient = http.Client();

final res = await _httpClient.get(
Uri.parse(url).replace(queryParameters: query),
headers: <String, String>{'Authorization': 'Bearer $bearerToken'},
);
if (res.statusCode != 200) {
throw HttpException('Failed ${res.reasonPhrase}');
}


return jsonDecode(res.body) as Map<String, dynamic>;
} on Exception catch (error) {
throw Exception(error);
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ homepage: https://twitter.com/0maru_dev
repository: https://github.com/0maru/twitter_login

environment:
sdk: '>=2.14.0 <4.0.0'
flutter: '>=3.3.0'
sdk: '>=3.2.4 <4.0.0'
flutter: '>=3.19.5'

dependencies:
crypto: ^3.0.1
crypto: ^3.0.3
flutter:
sdk: flutter
http: ^1.0.0
http: ^1.2.1

dev_dependencies:
flutter_test:
Expand Down