Skip to content

Commit

Permalink
Merge pull request #59 from EasyAbp/fix-login
Browse files Browse the repository at this point in the history
Add the `Scope` login input and rename the claim from `appid` to `wechat_appid`
  • Loading branch information
gdlcf88 committed Dec 3, 2022
2 parents fdfecb8 + 83c907e commit 8c66b73
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion common.props
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>1.4.3</Version>
<Version>1.5.0</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>
Expand Down
Expand Up @@ -23,5 +23,7 @@ public class LoginInput
/// 查找并使用最近一次登录的租户登录(忽略当前租户环境)
/// </summary>
public bool LookupUseRecentlyTenant { get; set; }

public string Scope { get; set; }
}
}
Expand Up @@ -8,5 +8,7 @@ public class PcLoginInput
{
[Required]
public string Token { get; set; }

public string Scope { get; set; }
}
}
Expand Up @@ -170,7 +170,7 @@ public virtual async Task<LoginOutput> LoginAsync(LoginInput input)
}

var response = await RequestAuthServerLoginAsync(input.AppId, loginResult.UnionId,
loginResult.Code2SessionResponse.OpenId);
loginResult.Code2SessionResponse.OpenId, input.Scope);

if (response.IsError)
{
Expand Down Expand Up @@ -341,7 +341,7 @@ protected virtual async Task TryRemoveUserInfoAsync(IdentityUser identityUser)
}
}

protected virtual async Task<TokenResponse> RequestAuthServerLoginAsync(string appId, string unionId, string openId)
protected virtual async Task<TokenResponse> RequestAuthServerLoginAsync(string appId, string unionId, string openId, string scope)
{
var client = _httpClientFactory.CreateClient(WeChatMiniProgramConsts.AuthServerHttpClientName);

Expand All @@ -358,6 +358,7 @@ protected virtual async Task<TokenResponse> RequestAuthServerLoginAsync(string a
{"appid", appId},
{"unionid", unionId},
{"openid", openId},
{"scope", scope},
}
};

Expand Down Expand Up @@ -497,7 +498,7 @@ public virtual async Task<PcLoginRequestTokensOutput> PcLoginRequestTokensAsync(
await _pcLoginAuthorizationCache.RemoveAsync(input.Token);

var response = await RequestAuthServerLoginAsync(cacheItem.AppId, cacheItem.UnionId,
cacheItem.OpenId);
cacheItem.OpenId, input.Scope);

if (response.IsError)
{
Expand Down
Expand Up @@ -20,6 +20,7 @@ public override void PreConfigureServices(ServiceConfigurationContext context)
builder.Configure(openIddictServerOptions =>
{
openIddictServerOptions.GrantTypes.Add(WeChatMiniProgramConsts.GrantType);
openIddictServerOptions.Claims.Add(WeChatMiniProgramConsts.AppIdClaim);
});
});
}
Expand All @@ -28,8 +29,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.Configure<AbpOpenIddictExtensionGrantsOptions>(options =>
{
options.Grants.Add(WeChatMiniProgramConsts.GrantType,
new WeChatMiniProgramTokenExtensionGrant());
options.Grants.Add(WeChatMiniProgramConsts.GrantType, new WeChatMiniProgramTokenExtensionGrant());
});
}
}
Expand Up @@ -94,7 +94,7 @@ public virtual async Task<IActionResult> HandleAsync(ExtensionGrantContext conte

principal.SetScopes(context.Request.GetScopes());
principal.SetResources(await GetResourcesAsync(context.Request.GetScopes(), scopeManager));
principal.SetClaim("appid", appId); // 记录 appid
principal.SetClaim(WeChatMiniProgramConsts.AppIdClaim, appId); // 记录 appid

await openIddictClaimDestinationsManager.SetAsync(principal);

Expand Down
Expand Up @@ -5,5 +5,7 @@ public class WeChatMiniProgramConsts
public const string GrantType = "WeChatMiniProgram_credentials";

public const string AuthServerHttpClientName = "EasyAbpWeChatMagementMiniProgram";

public const string AppIdClaim = "wechat_appid";
}
}
Expand Up @@ -39,7 +39,8 @@ public class FakeLoginAppService : LoginAppService
{
}

protected override Task<TokenResponse> RequestAuthServerLoginAsync(string appId, string unionId, string openId)
protected override Task<TokenResponse> RequestAuthServerLoginAsync(
string appId, string unionId, string openId, string scope)
{
return Task.FromResult(new TokenResponse());
}
Expand Down

0 comments on commit 8c66b73

Please sign in to comment.