参考资料
public static class Util
{
/// <summary>
/// Sets the cert policy.
/// </summary>
public static void SetCertificatePolicy()
{
ServicePointManager.ServerCertificateValidationCallback
+= RemoteCertificateValidate;
}
/// <summary>
/// Remotes the certificate validate.
/// </summary>
private static bool RemoteCertificateValidate(
object sender, X509Certificate cert,
X509Chain chain, SslPolicyErrors error)
{
return true;
}
}
private void InitializeWebServerClient()
{
var authorizationServerUri = new Uri(Paths.AuthorizationServerBaseAddress);
var authorizationServer = new AuthorizationServerDescription
{
AuthorizationEndpoint = new Uri(authorizationServerUri, Paths.AuthorizePath),
TokenEndpoint = new Uri(authorizationServerUri, Paths.TokenPath)
};
_webServerClient = new WebServerClient(authorizationServer, Clients.Client1.Id, Clients.Client1.Secret);
}
//请求https地址前
Util.SetCertificatePolicy();
var authorizationState = _webServerClient.ProcessUserAuthorization(Request);
//当 Oauth2 服务端 AllowInsecureHttp = false,
var userAuthorization = _webServerClient.PrepareRequestUserAuthorization(new[] { "bio", "notes" },"https://客户端接受authcode地址");
创建pfx的Visual Studio自带工具
makecert
,pvk2pfx