Skip to content

Commit

Permalink
feat: login with serverside(iOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
KangYee committed Feb 23, 2024
1 parent 2a88f6b commit afc260c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ios/Classes/TencentKitPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
result([NSNumber numberWithBool:[TencentOAuth iphoneTIMInstalled]]);
} else if ([@"login" isEqualToString:call.method]) {
[self login:call result:result];
} else if ([@"loginServerSide" isEqualToString:call.method]) {
[self loginServerSide:call result:result];
} else if ([@"logout" isEqualToString:call.method]) {
[self logout:call result:result];
} else if ([@"shareMood" isEqualToString:call.method]) {
Expand All @@ -88,6 +90,17 @@ - (void)login:(FlutterMethodCall *)call result:(FlutterResult)result {
if (_oauth != nil) {
NSString *scope = call.arguments[@"scope"];
NSArray *permissions = [scope componentsSeparatedByString:@","];
_oauth.authMode = kAuthModeClientSideToken;
[_oauth authorize:permissions];
}
result(nil);
}

- (void)loginServerSide:(FlutterMethodCall *)call result:(FlutterResult)result {
if (_oauth != nil) {
NSString *scope = call.arguments[@"scope"];
NSArray *permissions = [scope componentsSeparatedByString:@","];
_oauth.authMode = kAuthModeServerSideCode;
[_oauth authorize:permissions];
}
result(nil);
Expand Down Expand Up @@ -278,6 +291,11 @@ - (void)tencentDidLogin {
if (_oauth.accessToken != nil && _oauth.accessToken.length > 0) {
NSString *openId = _oauth.openId;
NSString *accessToken = _oauth.accessToken;
if (_oauth.authMode == kAuthModeServerSideCode) {
// 将 code 的值赋给 accessToken, 避免字段功能混淆
// 同时官方文档也有说明通过此接口获取的 code 实际上就是 accessToken
accessToken = [_oauth getServerSideCode];
}
long long expiresIn =
ceil(_oauth.expirationDate.timeIntervalSinceNow); // 向上取整
long long createAt = [[NSDate date] timeIntervalSince1970] * 1000.0;
Expand Down

0 comments on commit afc260c

Please sign in to comment.