मैं अपने स्पंदन ऐप से उपयोगकर्ता को Google API में लॉग इन करने का प्रयास कर रहा हूं, लेकिन टोकन को स्वचालित रूप से लाने के लिए इसे प्राप्त नहीं कर सकता। मुझे सबसे नज़दीकी स्क्रीन में टोकन स्ट्रिंग देखना था और इसे वापस ऐप में कॉपी/पेस्ट करने के लिए कहा गया। मुझे संदेह है कि यह redirect_uri पैरामीटर से संबंधित है।
मैंने oauth2_client और flutter_appauth और यह लगभग एक जैसा ही परिणाम है। क्लाइंट सेट करते समय, यदि मैं Google द्वारा प्रदान किए गए पहले रीडायरेक्ट_यूरी का उपयोग करता हूं urn:ietf:wg:oauth:2.0:oob
, तो अनुमति देने के बाद यह ऑथ स्क्रीन में टोकन दिखाता है और उपयोगकर्ता को इसे कॉपी करने और ऐप में वापस पेस्ट करने का निर्देश देता है। अगर मैं सहमति स्क्रीन के बजाय AndroidManifest.xml और build.gradle में सेट किए गए uri का उपयोग करता हूं, तो मुझे ब्राउज़र में यह संदेश मिलता है:
"Redirect_url के लिए अमान्य पैरामीटर मान: अनुपलब्ध योजना: ai.autonet.afterme"
अंत में, अगर मैं "http://localhost"
(Google द्वारा प्रदान की गई दूसरी यूरी) का उपयोग करता हूं, तो मुझे "अनुरोध का समय समाप्त" हो जाता है।
Google की ओर से मेरा क्लाइंट कॉन्फ़िगरेशन इस तरह दिखता है:
"client_id":"somethingsomething.apps.googleusercontent.com","project_id":"afterme-850af","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]
Flutter_appauth कार्यान्वयन का सबसे सरल संस्करण यहां दिया गया है:
main.dart
import 'package:flutter/material.dart';
import 'package:flutter_appauth/flutter_appauth.dart';
import 'package:oauth2_client/access_token_response.dart';
import 'package:http/http.dart' as http;
const AUTH_ENDIPOINT = 'https://accounts.google.com/o/oauth2/auth';
const CLIENT_ID =
'somethingsomething.apps.googleusercontent.com';
const REDIRECT_URI = 'ai.autonet.afterme';
const TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token";
var scopes = [
"https://www.googleapis.com/auth/youtube",
"https://www.googleapis.com/auth/youtube.upload",
];
void main() {
runApp(MyApp());
}
var httpClient = http.Client();
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
FlutterAppAuth appAuth = FlutterAppAuth();
authorize() async {
final AuthorizationTokenResponse result =
await appAuth.authorizeAndExchangeCode(AuthorizationTokenRequest(
CLIENT_ID, REDIRECT_URI,
serviceConfiguration: AuthorizationServiceConfiguration(
AUTH_ENDPOINT,
TOKEN_ENDPOINT),
scopes: scopes));
print(result.accessToken.toString());
}
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
getResources() async {
http.Response resp = await httpClient
.get('GET https://www.googleapis.com/youtube/v3/videos');
print(resp.body);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Text("Permission"), onPressed: () => widget.authorize()),
],
),
),
);
}
}
----------------------------------------------------------------
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ai.autonet.afterme">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="afterme"
android:icon="@mipmap/ic_launcher">
<activity android:name="com.linusu.flutter_web_auth.CallbackActivity" >
<intent-filter android:label="flutter_web_auth">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="ai.autonet.afterme" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
-------------------------------------------------------------------------------------
build.gradle:
...
defaultConfig {
applicationId "ai.autonet.afterme"
minSdkVersion 18
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
manifestPlaceholders = [
'appAuthRedirectScheme': 'ai.autonet.afterme'
]
}
...
किसी भी मदद को महत्व दिया जाएगा।
2 जवाब
क्या आपने अपनी योजना के अंत में ://
जोड़ने का प्रयास किया है? मुझे यकीन नहीं है कि आप Google को एक मान्य योजना नाम प्रदान कर रहे हैं।
क्या आप ai.autonet.afterme://
या ai.autonet.afterme://auth
आजमा सकते हैं?
आईओएस और एंड्रॉइड दोनों के लिए रिडायरेक्ट_यूरी को स्पंदन में सेट करने का सही तरीका इस प्रकार है:
पहला कदम Android - android/app/build.gradle के अंतर्गत
defaultConfig { applicationId "com.testingapp" // Set the applicationId minSdkVersion 18 targetSdkVersion 30 versionCode flutterVersionCode.toInteger() versionName flutterVersionName manifestPlaceholders = [ 'appAuthRedirectScheme': 'com.testingapp' // Add this also using your application ID URI as the based for all your derived URi ] }
आईओएस - आईओएस/धावक/Info.plist
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.testingapp</string> //Again Application Id should be added here
</array>
</dict>
</array>
...
फिर अपने ऐप में आप इसे इस प्रकार उपयोग कर सकते हैं:
const AUTH0_REDIRECT_URI = "com.testingapp://login-callback";
कृपया ध्यान दें "://login-callback" यहां एप्लिकेशन आईडी में जोड़ा गया है, इसे कहीं और परिभाषित नहीं किया गया है।
अंत में अपने प्रदाता में इसे भी जोड़ें। मेरे मामले में मैं keycloak का उपयोग कर रहा हूँ।
संबंधित सवाल
जुड़े हुए प्रश्न
नए सवाल
android
एंड्रॉइड Google का मोबाइल ऑपरेटिंग सिस्टम है, जिसका उपयोग प्रोग्रामिंग या डिजिटल डिवाइस (स्मार्टफोन, टैबलेट, ऑटोमोबाइल्स, टीवी, वियर, ग्लास, IoT) को विकसित करने के लिए किया जाता है। एंड्रॉइड से संबंधित विषयों के लिए, एंड्रॉइड-विशिष्ट टैग जैसे कि एंड्रॉइड-इरादे, एंड्रॉइड-गतिविधि, एंड्रॉइड-एडॉप्टर आदि का उपयोग करें। विकास या प्रोग्रामिंग के अलावा अन्य प्रश्नों के लिए, लेकिन एंड्रॉइड फ्रेमवर्क से संबंधित हैं, इस लिंक का उपयोग करें: https: // android.stackexchange.com।