1. 程式人生 > >補充ABP Zero集成微信小程序登陸的BUG修復部分

補充ABP Zero集成微信小程序登陸的BUG修復部分

err post seconds ride rac oid result 戶外 xxx

感謝園友 @turingguo 發布的 https://www.cnblogs.com/turingguo/p/9019026.html 文章,詳細介紹了ABP Zero集成微信小程序登陸的實現過程。

經測試,abp的外部登陸有幾處bug,在此做記錄。

1、xxxxWebHostModule.cs文件

 1         public override void PostInitialize()
 2         {
 3 
 4             if (!IocManager.Resolve<IMultiTenancyConfig>().IsEnabled)
 5             {
6 return; 7 } 8 9 if (!DatabaseCheckHelper.Exist(_appConfiguration["ConnectionStrings:Default"])) 10 { 11 return; 12 } 13 14 var workManager = IocManager.Resolve<IBackgroundWorkerManager>(); 15 workManager.Add(IocManager.Resolve<SubscriptionExpirationCheckWorker>());
16 workManager.Add(IocManager.Resolve<SubscriptionExpireEmailNotifierWorker>()); 17 18 ConfigureExternalAuthProviders(); 19 }

當啟用多租戶模式的情況下,租主站點沒有將外部登陸的provider添加到集合中。

不未啟用多租戶模式時,第四行的邏輯判斷又給跳過了。

因此將18行代碼調整到第3行。

2、TokenAuthController文件

 1 public async Task<ExternalAuthenticateResultModel> ExternalAuthenticate([FromBody] ExternalAuthenticateModel model)
2 { 3 var externalUser = await GetExternalUserInfo(model); 4 5 var loginResult = await _logInManager.LoginAsync(new UserLoginInfo(model.AuthProvider, externalUser.ProviderKey, model.AuthProvider), GetTenancyNameOrNull()); 6 7 switch (loginResult.Result) 8 { 9 case AbpLoginResultType.Success: 10 { 11 var accessToken = CreateAccessToken(CreateJwtClaims(loginResult.Identity)); 12 13 var returnUrl = model.ReturnUrl; 14 15 if (model.SingleSignIn.HasValue && model.SingleSignIn.Value && loginResult.Result == AbpLoginResultType.Success) 16 { 17 loginResult.User.SetSignInToken(); 18 returnUrl = AddSingleSignInParametersToReturnUrl(model.ReturnUrl, loginResult.User.SignInToken, loginResult.User.Id, loginResult.User.TenantId); 19 } 20 21 return new ExternalAuthenticateResultModel 22 { 23 AccessToken = accessToken, 24 EncryptedAccessToken = GetEncrpyedAccessToken(accessToken), 25 ExpireInSeconds = (int)_configuration.Expiration.TotalSeconds, 26 ReturnUrl = returnUrl 27 }; 28 } 29 case AbpLoginResultType.UnknownExternalLogin: 30 { 31 var newUser = await RegisterExternalUserAsync(externalUser); 32 if (!newUser.IsActive) 33 { 34 return new ExternalAuthenticateResultModel 35 { 36 WaitingForActivation = true 37 }; 38 } 39 40 //Try to login again with newly registered user! 41 loginResult = await _logInManager.LoginAsync(new UserLoginInfo(model.AuthProvider, externalUser.ProviderKey, model.AuthProvider), GetTenancyNameOrNull()); 42 if (loginResult.Result != AbpLoginResultType.Success) 43 { 44 throw _abpLoginResultTypeHelper.CreateExceptionForFailedLoginAttempt( 45 loginResult.Result, 46 model.ProviderKey, 47 GetTenancyNameOrNull() 48 ); 49 } 50 51 var accessToken = CreateAccessToken(CreateJwtClaims(loginResult.Identity)); 52 return new ExternalAuthenticateResultModel 53 { 54 AccessToken = accessToken, 55 EncryptedAccessToken = GetEncrpyedAccessToken(accessToken), 56 ExpireInSeconds = (int)_configuration.Expiration.TotalSeconds 57 }; 58 } 59 default: 60 { 61 throw _abpLoginResultTypeHelper.CreateExceptionForFailedLoginAttempt( 62 loginResult.Result, 63 model.ProviderKey, 64 GetTenancyNameOrNull() 65 ); 66 } 67 } 68 }

分別在第5行和41行,是用戶外部登陸的過程。該兩行代碼的BUG是,登陸時使用了微信的accessCode當作providerKey登陸,方法是將 await GetExternalUserInfo(model) 返回的ProviderKey做為用戶登陸就可以了。(以上代碼是修改後的代碼)

補充ABP Zero集成微信小程序登陸的BUG修復部分