From 8d0deaebba9c2eeb977efcc5d003c987bb0a2a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= <454313500@qq.com> Date: Mon, 8 Jan 2024 11:17:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E7=99=BB=E5=BD=95=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthenticationConstants.cs | 16 ++++++++++ .../AuthenticationOAuthOptions.cs | 15 ++++++++++ .../AuthticationErrCodeModel.cs | 27 +++++++++++++++++ .../Gitee/GiteeAuthenticationConstants.cs | 4 --- .../Gitee/GiteeAuthenticationHandler.cs | 12 ++------ .../Gitee/GiteeAuthenticationOptions.cs | 9 ++---- .../Gitee/GiteeAuthticationErrCodeModel.cs | 30 ------------------- .../OAuthAuthenticationHandler.cs | 2 +- .../QQ/QQAuthenticationConstants.cs | 4 --- .../QQ/QQAuthenticationHandler.cs | 11 ++----- .../QQ/QQAuthenticationOptions.cs | 4 +-- .../QQ/QQAuthticationErrCodeModel.cs | 30 ------------------- 12 files changed, 69 insertions(+), 95 deletions(-) create mode 100644 Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/AuthenticationConstants.cs create mode 100644 Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/AuthenticationOAuthOptions.cs create mode 100644 Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/AuthticationErrCodeModel.cs delete mode 100644 Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthticationErrCodeModel.cs delete mode 100644 Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthticationErrCodeModel.cs diff --git a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/AuthenticationConstants.cs b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/AuthenticationConstants.cs new file mode 100644 index 00000000..5a459a10 --- /dev/null +++ b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/AuthenticationConstants.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.AspNetCore.Authentication.OAuth +{ + public class AuthenticationConstants + { + public const string OpenId = "urn:openid"; + public const string AccessToken = "urn:access_token"; + public const string Name = "urn:name"; + + } +} diff --git a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/AuthenticationOAuthOptions.cs b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/AuthenticationOAuthOptions.cs new file mode 100644 index 00000000..187a9f80 --- /dev/null +++ b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/AuthenticationOAuthOptions.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication.OAuth; + +namespace Yi.Framework.AspNetCore.Authentication.OAuth +{ + public class AuthenticationOAuthOptions:OAuthOptions + { + + public string RedirectUri { get; set; } + } +} diff --git a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/AuthticationErrCodeModel.cs b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/AuthticationErrCodeModel.cs new file mode 100644 index 00000000..59048894 --- /dev/null +++ b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/AuthticationErrCodeModel.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.AspNetCore.Authentication.OAuth.Gitee; + +namespace Yi.Framework.AspNetCore.Authentication.OAuth +{ + public class AuthticationErrCodeModel + { + public string error { get; set; } + + public string error_description { get; set; } + + public static void VerifyErrResponse(string content) + { + + var model = Newtonsoft.Json.JsonConvert.DeserializeObject(content); + if (model.error != null) + { + + throw new Exception($"第三方授权返回错误,错误码:【{model.error}】,错误详情:【{model.error_description}】"); + } + } + } +} diff --git a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthenticationConstants.cs b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthenticationConstants.cs index ba665ab5..73106b51 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthenticationConstants.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthenticationConstants.cs @@ -15,9 +15,5 @@ public static class GiteeAuthenticationConstants { public const string Url = "urn:gitee:url"; public const string AvatarUrl = "urn:gitee:avatarUrl"; - - public const string OpenId = "urn:openid"; - public const string AccessToken = "urn:access_token"; - public const string Name = "urn:name"; } } diff --git a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthenticationHandler.cs b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthenticationHandler.cs index f88e6d3e..e1a7ace0 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthenticationHandler.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthenticationHandler.cs @@ -2,7 +2,6 @@ using System.Text.Encodings.Web; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Yi.Framework.AspNetCore.Authentication.OAuth.QQ; using static Yi.Framework.AspNetCore.Authentication.OAuth.Gitee.GiteeAuthenticationConstants; namespace Yi.Framework.AspNetCore.Authentication.OAuth.Gitee @@ -40,16 +39,11 @@ namespace Yi.Framework.AspNetCore.Authentication.OAuth.Gitee new Claim(Claims.AvatarUrl, userInfoMdoel.avatar_url), new Claim(Claims.Url, userInfoMdoel.url), - new Claim(Claims.OpenId,userInfoMdoel.id.ToString()), - new Claim(Claims.Name, userInfoMdoel.name), - new Claim(Claims.AccessToken, tokenModel.access_token) + new Claim(AuthenticationConstants.OpenId,userInfoMdoel.id.ToString()), + new Claim(AuthenticationConstants.Name, userInfoMdoel.name), + new Claim(AuthenticationConstants.AccessToken, tokenModel.access_token) }; return claims; } - - protected override void VerifyErrResponse(string content) - { - GiteeAuthticationErrCodeModel.VerifyErrResponse(content); - } } } diff --git a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthenticationOptions.cs b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthenticationOptions.cs index 0139fe38..bd1b4c1d 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthenticationOptions.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthenticationOptions.cs @@ -6,7 +6,6 @@ using System.Security.Claims; using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.OAuth; using static Yi.Framework.AspNetCore.Authentication.OAuth.Gitee.GiteeAuthenticationConstants; namespace Yi.Framework.AspNetCore.Authentication.OAuth.Gitee; @@ -14,7 +13,7 @@ namespace Yi.Framework.AspNetCore.Authentication.OAuth.Gitee; /// /// Defines a set of options used by . /// -public class GiteeAuthenticationOptions : OAuthOptions +public class GiteeAuthenticationOptions : AuthenticationOAuthOptions { public GiteeAuthenticationOptions() { @@ -33,7 +32,7 @@ public class GiteeAuthenticationOptions : OAuthOptions ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id"); ClaimActions.MapJsonKey(ClaimTypes.Name, "login"); ClaimActions.MapJsonKey(ClaimTypes.Email, "email"); - ClaimActions.MapJsonKey(Claims.Name, "name"); + ClaimActions.MapJsonKey(ClaimTypes.Name, "name"); ClaimActions.MapJsonKey(Claims.Url, "url"); } @@ -42,6 +41,4 @@ public class GiteeAuthenticationOptions : OAuthOptions /// the email addresses associated with the logged in user. /// public string UserEmailsEndpoint { get; set; } - - public string RedirectUri { get; set; } -} +} \ No newline at end of file diff --git a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthticationErrCodeModel.cs b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthticationErrCodeModel.cs deleted file mode 100644 index a1cba0f5..00000000 --- a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/Gitee/GiteeAuthticationErrCodeModel.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json; -using System.Threading.Tasks; - - -namespace Yi.Framework.AspNetCore.Authentication.OAuth.Gitee -{ - public class GiteeAuthticationErrCodeModel - { - public string error { get; set; } - - public string error_description { get; set; } - - public static void VerifyErrResponse(string content) - { - - var model =Newtonsoft.Json.JsonConvert.DeserializeObject (content); - if (model.error != null) - { - - throw new Exception($"第三方授权返回错误,错误码:【{model.error}】,错误详情:【{model.error_description}】"); - } - } - - } - -} diff --git a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/OAuthAuthenticationHandler.cs b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/OAuthAuthenticationHandler.cs index 4fedae7c..8e4ce9dc 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/OAuthAuthenticationHandler.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/OAuthAuthenticationHandler.cs @@ -63,7 +63,7 @@ namespace Yi.Framework.AspNetCore.Authentication.OAuth protected virtual void VerifyErrResponse(string content) { - return; + AuthticationErrCodeModel.VerifyErrResponse(content); } protected abstract Task> GetAuthTicketAsync(string code); diff --git a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthenticationConstants.cs b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthenticationConstants.cs index bac733fa..ca46dcf7 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthenticationConstants.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthenticationConstants.cs @@ -19,9 +19,5 @@ public static class QQAuthenticationConstants public const string PictureMediumUrl = "urn:qq:picture_medium"; public const string PictureUrl = "urn:qq:picture"; public const string UnionId = "urn:qq:unionid"; - - public const string OpenId = "urn:openid"; - public const string AccessToken = "urn:access_token"; - public const string Name = "urn:name"; } } diff --git a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthenticationHandler.cs b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthenticationHandler.cs index 3f342496..fb79675c 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthenticationHandler.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthenticationHandler.cs @@ -14,11 +14,6 @@ namespace Yi.Framework.AspNetCore.Authentication.OAuth.QQ public override string AuthenticationSchemeNmae => QQAuthenticationDefaults.AuthenticationScheme; - protected override void VerifyErrResponse(string content) - { - QQAuthticationErrCodeModel.VerifyErrResponse(content); - } - protected override async Task> GetAuthTicketAsync(string code) { @@ -58,9 +53,9 @@ namespace Yi.Framework.AspNetCore.Authentication.OAuth.QQ new Claim(Claims.PictureMediumUrl, userInfoMdoel.figureurl_qq_1), new Claim(Claims.PictureUrl, userInfoMdoel.figureurl), - new Claim(Claims.OpenId, tokenModel.openid), - new Claim(Claims.Name, userInfoMdoel.nickname), - new Claim(Claims.AccessToken, tokenModel.access_token), + new Claim(AuthenticationConstants.OpenId, tokenModel.openid), + new Claim(AuthenticationConstants.Name, userInfoMdoel.nickname), + new Claim(AuthenticationConstants.AccessToken, tokenModel.access_token), }; return claims; diff --git a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthenticationOptions.cs b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthenticationOptions.cs index c82c44d2..9784474f 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthenticationOptions.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthenticationOptions.cs @@ -6,7 +6,6 @@ using System.Security.Claims; using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.OAuth; using static Yi.Framework.AspNetCore.Authentication.OAuth.QQ.QQAuthenticationConstants; namespace Yi.Framework.AspNetCore.Authentication.OAuth.QQ; @@ -14,7 +13,7 @@ namespace Yi.Framework.AspNetCore.Authentication.OAuth.QQ; /// /// Defines a set of options used by . /// -public class QQAuthenticationOptions : OAuthOptions +public class QQAuthenticationOptions : AuthenticationOAuthOptions { public QQAuthenticationOptions() { @@ -47,5 +46,4 @@ public class QQAuthenticationOptions : OAuthOptions /// public string UserIdentificationEndpoint { get; set; } - public string RedirectUri { get; set; } } diff --git a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthticationErrCodeModel.cs b/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthticationErrCodeModel.cs deleted file mode 100644 index b84824bf..00000000 --- a/Yi.Abp.Net8/framework/Yi.Framework.AspNetCore.Authentication.OAuth/QQ/QQAuthticationErrCodeModel.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json; -using System.Threading.Tasks; - - -namespace Yi.Framework.AspNetCore.Authentication.OAuth.QQ -{ - public class QQAuthticationErrCodeModel - { - public string error { get; set; } - - public string error_description { get; set; } - - public static void VerifyErrResponse(string content) - { - - var model =Newtonsoft.Json.JsonConvert.DeserializeObject (content); - if (model.error != null) - { - - throw new Exception($"第三方授权返回错误,错误码:【{model.error}】,错误详情:【{model.error_description}】"); - } - } - - } - -}