add impl for QRCode login in both client & server mode

Signed-off-by: yeliulee <yeliuleet@gmail.com>
This commit is contained in:
yeliulee
2024-11-05 22:51:12 +08:00
parent 31ef82872d
commit 2a8044292b
4 changed files with 32 additions and 4 deletions

View File

@ -181,16 +181,18 @@ public class TencentKitPlugin implements FlutterPlugin, ActivityAware, ActivityR
private void login(@NonNull MethodCall call, @NonNull Result result) {
final String scope = call.argument("scope");
final boolean qrcode = call.argument("qrcode");
if (tencent != null) {
tencent.login(activityPluginBinding.getActivity(), scope, loginListener);
tencent.login(activityPluginBinding.getActivity(), scope, loginListener, qrcode);
}
result.success(null);
}
private void loginServerSide(@NonNull MethodCall call, @NonNull Result result) {
final String scope = call.argument("scope");
final boolean qrcode = call.argument("qrcode");
if (tencent != null) {
tencent.loginServerSide(activityPluginBinding.getActivity(), scope, loginListener);
tencent.loginServerSide(activityPluginBinding.getActivity(), scope, loginListener, qrcode);
}
result.success(null);
}

View File

@ -24,6 +24,7 @@ enum TencentRetCode {
@implementation TencentKitPlugin {
FlutterMethodChannel *_channel;
TencentOAuth *_oauth;
BOOL _forceWebLogin;
}
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
@ -41,6 +42,7 @@ enum TencentRetCode {
if (self) {
_channel = channel;
}
_forceWebLogin = NO;
return self;
}
@ -90,8 +92,15 @@ enum TencentRetCode {
if (_oauth != nil) {
NSString *scope = call.arguments[@"scope"];
NSArray *permissions = [scope componentsSeparatedByString:@","];
NSNumber *qrcode = call.arguments[@"qrcode"];
_oauth.authMode = kAuthModeClientSideToken;
[_oauth authorize:permissions];
if ([qrcode boolValue]) {
_forceWebLogin = YES;
[_oauth authorizeWithQRlogin:permissions];
} else {
_forceWebLogin = NO;
[_oauth authorize:permissions];
}
}
result(nil);
}
@ -100,8 +109,15 @@ enum TencentRetCode {
if (_oauth != nil) {
NSString *scope = call.arguments[@"scope"];
NSArray *permissions = [scope componentsSeparatedByString:@","];
NSNumber *qrcode = call.arguments[@"qrcode"];
_oauth.authMode = kAuthModeServerSideCode;
[_oauth authorize:permissions];
if ([qrcode boolValue]) {
_forceWebLogin = YES;
[_oauth authorizeWithQRlogin:permissions];
} else {
_forceWebLogin = NO;
[_oauth authorize:permissions];
}
}
result(nil);
}
@ -286,6 +302,10 @@ enum TencentRetCode {
#pragma mark - TencentSessionDelegate
- (BOOL)forceWebLogin {
return _forceWebLogin;
}
- (void)tencentDidLogin {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
if (_oauth.accessToken != nil && _oauth.accessToken.length > 0) {

View File

@ -74,11 +74,13 @@ class MethodChannelTencentKit extends TencentKitPlatform {
@override
Future<void> login({
required List<String> scope,
bool qrcode = false,
}) {
return methodChannel.invokeMethod<void>(
'login',
<String, dynamic>{
'scope': scope.join(','),
'qrcode': qrcode,
},
);
}
@ -86,11 +88,13 @@ class MethodChannelTencentKit extends TencentKitPlatform {
@override
Future<void> loginServerSide({
required List<String> scope,
bool qrcode = false,
}) {
return methodChannel.invokeMethod<void>(
'loginServerSide',
<String, dynamic>{
'scope': scope.join(','),
'qrcode': qrcode,
},
);
}

View File

@ -60,6 +60,7 @@ abstract class TencentKitPlatform extends PlatformInterface {
/// 登录
Future<void> login({
required List<String> scope,
bool qrcode = false,
}) {
throw UnimplementedError(
'login({required scope}) has not been implemented.');
@ -68,6 +69,7 @@ abstract class TencentKitPlatform extends PlatformInterface {
/// 登录Server-Side
Future<void> loginServerSide({
required List<String> scope,
bool qrcode = false,
}) {
throw UnimplementedError(
'loginServerSide({required scope}) has not been implemented.');