Page tree
Skip to end of metadata
Go to start of metadata


(1)在葡萄城报表的安装目录中提供了用于单点登录的安全提供器的模块以及示例,默认安装路径为:C:\ActiveReports 11 报表服务器\SDK\Samples\ActiveTunes.SecurityProvider。

(2)在Visual Studio中新建.NET FW4.5的Class library项目, 命名为WeChatSecurityProvider。
(3)通过NuGet添加Senparc.Weixin.QY
(4)添加葡萄城报表安全提供器开发程序集ActiveReports.Server.Extensibility.dll
(5)新建WeChatSecurityProviderFactory class 实现 ActiveReports.Server.Security. ISecurityProviderFactory接口。实现代码大致如下:

public class WeChatSecurityProviderFactory : ISecurityProviderFactory
{
public ISecurityProvider Create(IDictionary<string, string> settings)
{
return new WeChatSecurityProvider(settings);
}

public IEnumerable<string> GetSupportedSettings()
{
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b16ec7a6-1689-46dc-b2fd-cb497e459c81"><ac:plain-text-body><![CDATA[ return new string[]
]]></ac:plain-text-body></ac:structured-macro>
{
QYHelper.CorpIDKey, // AgentId
QYHelper.CorpSecretKey, // Secret
QYHelper.ProxyNameKey,
QYHelper.ProxyPortKey,
QYHelper.ProxyUserPasswordKey,
QYHelper.ProxyUserNameKey,
QYHelper.ProxyUserDomainKey,
};
}
}

(6)新建WeChatSecurityProvider class 实现ISecurityProvider,其中最主要的是 ValidateToken 和 GetUserContext 接口。大致实现代码:

public class WeChatSecurityProvider : ISecurityProvider
{
public bool ValidateToken(string token)
{
Cache<UserInfo> cache;
return _tokenCacheManager.TryGetOrCreate(token, out cache);
}
public UserContext GetUserContext(string token)
{
Cache<UserInfo> cache;
string name = null;
if(_tokenCacheManager.TryGetOrCreate(token, out cache))
{
name = cache.Content.Raw.UserId;
}

return new WeChatUserContext(name);
}
……
}

internal class UserInfoCacheManager
{
……
public bool TryGetOrCreate(string code, out Cache<UserInfo> content)
{
content = null;
if (TryGet(code, out content)) return true;

ErrorJsonResultException ex;
var userInfo = QYHelper.GetUserInfo(code, out ex); // Call WeChat API to get use info
if (ex != null

userInfo == null) return false;

content = Create(new UserInfo(code, userInfo));
return true;
}
}
public class WeChatUserContext : UserContext
{
public WeChatUserContext(string weChatName)
{
WeChatName = weChatName;
}
public string WeChatName { get; }
public override string GetValue(string key)
{
if (string.Equals(key, "Role")) return "WeChat";
if (string.Equals(key, "WeChatName")) return WeChatName;
return null;
}
……
}


(7)编译项目将生成的dll拷贝到报表服务器的SecurityProviders目录下,默认路径是C:\ActiveReports 11 报表服务器\SecurityProviders

  • No labels