예제 #1
0
        public async Task <Unit> Handle(AuthorizationCallbackCommand request, CancellationToken cancellationToken)
        {
            var authorizationInfo =
                await _thirdPartyOauthService.GetAuthorizationInformationAsync(
                    new GetAuthorizationInformationInput(request.AuthCode));

            var authorizerInfo =
                await _thirdPartyOauthService.GetAuthorizerInfoAsync(
                    new GetAuthorizerInfoInput(authorizationInfo.AuthorizationInfo.AuthorizerAppId));

            //小程序授权先不做
            if (authorizerInfo.AuthorizerInfo.MiniProgramInfo != null)
            {
                return(Unit.Value);
            }

            var officialAccount = new OfficialAccounts(authorizerInfo.AuthorizationInfo.AuthorizerAppId, authorizerInfo.AuthorizerInfo.UserName)
            {
                NickName        = authorizerInfo.AuthorizerInfo.NickName,
                HeadImg         = authorizerInfo.AuthorizerInfo.HeadImg,
                ServiceTypeInfo = (EnumOfficialAccountsServiceType)authorizerInfo.AuthorizerInfo.ServiceTypeInfo.Id,
                VerifyTypeInfo  = (EnumOfficialAccountsVerifyType)authorizerInfo.AuthorizerInfo.VerifyTypeInfo.Id,
                Idc             = authorizerInfo.AuthorizerInfo.Idc,
                PrincipalName   = authorizerInfo.AuthorizerInfo.PrincipalName,
                QrCodeUrl       = authorizerInfo.AuthorizerInfo.QrCodeUrl,
                Alias           = authorizerInfo.AuthorizerInfo.Alias,
                Signature       = authorizerInfo.AuthorizerInfo.Signature,
                RefreshToken    = authorizerInfo.AuthorizationInfo.AuthorizerRefreshToken
            };

            await _officialAccountRepository.AddAsync(officialAccount, cancellationToken);

            await _officialAccountRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }