mirror of
https://github.com/RxReader/tencent_kit.git
synced 2025-07-04 12:18:01 +08:00
add impl for QRCode login in both client & server mode
Signed-off-by: yeliulee <yeliuleet@gmail.com>
This commit is contained in:
@ -181,16 +181,18 @@ public class TencentKitPlugin implements FlutterPlugin, ActivityAware, ActivityR
|
|||||||
|
|
||||||
private void login(@NonNull MethodCall call, @NonNull Result result) {
|
private void login(@NonNull MethodCall call, @NonNull Result result) {
|
||||||
final String scope = call.argument("scope");
|
final String scope = call.argument("scope");
|
||||||
|
final boolean qrcode = call.argument("qrcode");
|
||||||
if (tencent != null) {
|
if (tencent != null) {
|
||||||
tencent.login(activityPluginBinding.getActivity(), scope, loginListener);
|
tencent.login(activityPluginBinding.getActivity(), scope, loginListener, qrcode);
|
||||||
}
|
}
|
||||||
result.success(null);
|
result.success(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loginServerSide(@NonNull MethodCall call, @NonNull Result result) {
|
private void loginServerSide(@NonNull MethodCall call, @NonNull Result result) {
|
||||||
final String scope = call.argument("scope");
|
final String scope = call.argument("scope");
|
||||||
|
final boolean qrcode = call.argument("qrcode");
|
||||||
if (tencent != null) {
|
if (tencent != null) {
|
||||||
tencent.loginServerSide(activityPluginBinding.getActivity(), scope, loginListener);
|
tencent.loginServerSide(activityPluginBinding.getActivity(), scope, loginListener, qrcode);
|
||||||
}
|
}
|
||||||
result.success(null);
|
result.success(null);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ enum TencentRetCode {
|
|||||||
@implementation TencentKitPlugin {
|
@implementation TencentKitPlugin {
|
||||||
FlutterMethodChannel *_channel;
|
FlutterMethodChannel *_channel;
|
||||||
TencentOAuth *_oauth;
|
TencentOAuth *_oauth;
|
||||||
|
BOOL _forceWebLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
|
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
|
||||||
@ -41,6 +42,7 @@ enum TencentRetCode {
|
|||||||
if (self) {
|
if (self) {
|
||||||
_channel = channel;
|
_channel = channel;
|
||||||
}
|
}
|
||||||
|
_forceWebLogin = NO;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,9 +92,16 @@ enum TencentRetCode {
|
|||||||
if (_oauth != nil) {
|
if (_oauth != nil) {
|
||||||
NSString *scope = call.arguments[@"scope"];
|
NSString *scope = call.arguments[@"scope"];
|
||||||
NSArray *permissions = [scope componentsSeparatedByString:@","];
|
NSArray *permissions = [scope componentsSeparatedByString:@","];
|
||||||
|
NSNumber *qrcode = call.arguments[@"qrcode"];
|
||||||
_oauth.authMode = kAuthModeClientSideToken;
|
_oauth.authMode = kAuthModeClientSideToken;
|
||||||
|
if ([qrcode boolValue]) {
|
||||||
|
_forceWebLogin = YES;
|
||||||
|
[_oauth authorizeWithQRlogin:permissions];
|
||||||
|
} else {
|
||||||
|
_forceWebLogin = NO;
|
||||||
[_oauth authorize:permissions];
|
[_oauth authorize:permissions];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
result(nil);
|
result(nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,9 +109,16 @@ enum TencentRetCode {
|
|||||||
if (_oauth != nil) {
|
if (_oauth != nil) {
|
||||||
NSString *scope = call.arguments[@"scope"];
|
NSString *scope = call.arguments[@"scope"];
|
||||||
NSArray *permissions = [scope componentsSeparatedByString:@","];
|
NSArray *permissions = [scope componentsSeparatedByString:@","];
|
||||||
|
NSNumber *qrcode = call.arguments[@"qrcode"];
|
||||||
_oauth.authMode = kAuthModeServerSideCode;
|
_oauth.authMode = kAuthModeServerSideCode;
|
||||||
|
if ([qrcode boolValue]) {
|
||||||
|
_forceWebLogin = YES;
|
||||||
|
[_oauth authorizeWithQRlogin:permissions];
|
||||||
|
} else {
|
||||||
|
_forceWebLogin = NO;
|
||||||
[_oauth authorize:permissions];
|
[_oauth authorize:permissions];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
result(nil);
|
result(nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,6 +302,10 @@ enum TencentRetCode {
|
|||||||
|
|
||||||
#pragma mark - TencentSessionDelegate
|
#pragma mark - TencentSessionDelegate
|
||||||
|
|
||||||
|
- (BOOL)forceWebLogin {
|
||||||
|
return _forceWebLogin;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)tencentDidLogin {
|
- (void)tencentDidLogin {
|
||||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||||
if (_oauth.accessToken != nil && _oauth.accessToken.length > 0) {
|
if (_oauth.accessToken != nil && _oauth.accessToken.length > 0) {
|
||||||
|
@ -74,11 +74,13 @@ class MethodChannelTencentKit extends TencentKitPlatform {
|
|||||||
@override
|
@override
|
||||||
Future<void> login({
|
Future<void> login({
|
||||||
required List<String> scope,
|
required List<String> scope,
|
||||||
|
bool qrcode = false,
|
||||||
}) {
|
}) {
|
||||||
return methodChannel.invokeMethod<void>(
|
return methodChannel.invokeMethod<void>(
|
||||||
'login',
|
'login',
|
||||||
<String, dynamic>{
|
<String, dynamic>{
|
||||||
'scope': scope.join(','),
|
'scope': scope.join(','),
|
||||||
|
'qrcode': qrcode,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -86,11 +88,13 @@ class MethodChannelTencentKit extends TencentKitPlatform {
|
|||||||
@override
|
@override
|
||||||
Future<void> loginServerSide({
|
Future<void> loginServerSide({
|
||||||
required List<String> scope,
|
required List<String> scope,
|
||||||
|
bool qrcode = false,
|
||||||
}) {
|
}) {
|
||||||
return methodChannel.invokeMethod<void>(
|
return methodChannel.invokeMethod<void>(
|
||||||
'loginServerSide',
|
'loginServerSide',
|
||||||
<String, dynamic>{
|
<String, dynamic>{
|
||||||
'scope': scope.join(','),
|
'scope': scope.join(','),
|
||||||
|
'qrcode': qrcode,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,7 @@ abstract class TencentKitPlatform extends PlatformInterface {
|
|||||||
/// 登录
|
/// 登录
|
||||||
Future<void> login({
|
Future<void> login({
|
||||||
required List<String> scope,
|
required List<String> scope,
|
||||||
|
bool qrcode = false,
|
||||||
}) {
|
}) {
|
||||||
throw UnimplementedError(
|
throw UnimplementedError(
|
||||||
'login({required scope}) has not been implemented.');
|
'login({required scope}) has not been implemented.');
|
||||||
@ -68,6 +69,7 @@ abstract class TencentKitPlatform extends PlatformInterface {
|
|||||||
/// 登录(Server-Side)
|
/// 登录(Server-Side)
|
||||||
Future<void> loginServerSide({
|
Future<void> loginServerSide({
|
||||||
required List<String> scope,
|
required List<String> scope,
|
||||||
|
bool qrcode = false,
|
||||||
}) {
|
}) {
|
||||||
throw UnimplementedError(
|
throw UnimplementedError(
|
||||||
'loginServerSide({required scope}) has not been implemented.');
|
'loginServerSide({required scope}) has not been implemented.');
|
||||||
|
Reference in New Issue
Block a user