diff --git a/android/build.gradle b/android/build.gradle index 0259d12..92126b7 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -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" } diff --git a/android/gradle.properties b/android/gradle.properties index 38c8d45..c765800 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -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 + diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 5a46cfa..7f23a3a 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -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 @@ -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 diff --git a/example/android/build.gradle b/example/android/build.gradle index 3088eed..2a8cd32 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 94adc3a..fc88bfa 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -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 + diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 3c9d085..ceccc3a 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/lib/entity/user.dart b/lib/entity/user.dart index aaf9073..8361ce7 100644 --- a/lib/entity/user.dart +++ b/lib/entity/user.dart @@ -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; @@ -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!, ); diff --git a/lib/schemes/access_token.dart b/lib/schemes/access_token.dart index fe7ba21..172c8e3 100644 --- a/lib/schemes/access_token.dart +++ b/lib/schemes/access_token.dart @@ -31,6 +31,7 @@ class AccessToken { if (params == null) { throw Exception(); } + return AccessToken(params); } } diff --git a/lib/src/oauth_2.dart b/lib/src/oauth_2.dart index da97aac..818ea47 100644 --- a/lib/src/oauth_2.dart +++ b/lib/src/oauth_2.dart @@ -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 getBearerToken({ diff --git a/lib/src/twitter_login.dart b/lib/src/twitter_login.dart index 55f711e..0a20784 100644 --- a/lib/src/twitter_login.dart +++ b/lib/src/twitter_login.dart @@ -125,7 +125,6 @@ class TwitterLogin { if (queries['denied'] != null) { throw const CanceledByUserException(); } - final token = await AccessToken.getAccessToken( apiKey, apiSecretKey, @@ -244,6 +243,7 @@ class TwitterLogin { } final queries = Uri.splitQueryString(Uri.parse(resultURI!).query); + if (queries['error'] != null) { throw Exception('Error Response: ${queries['error']}'); } diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 1bc0498..0c56208 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -98,6 +98,7 @@ Future> httpGetFromBearerToken( }) async { try { final _httpClient = http.Client(); + final res = await _httpClient.get( Uri.parse(url).replace(queryParameters: query), headers: {'Authorization': 'Bearer $bearerToken'}, @@ -105,6 +106,8 @@ Future> httpGetFromBearerToken( if (res.statusCode != 200) { throw HttpException('Failed ${res.reasonPhrase}'); } + + return jsonDecode(res.body) as Map; } on Exception catch (error) { throw Exception(error); diff --git a/pubspec.yaml b/pubspec.yaml index 3e459a1..13cea28 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: