This repository was archived by the owner on Apr 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathPrivateAuthenticator.cs
More file actions
51 lines (41 loc) · 1.53 KB
/
PrivateAuthenticator.cs
File metadata and controls
51 lines (41 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Security.Cryptography.X509Certificates;
using Xero.Api.Infrastructure.Interfaces;
using Xero.Api.Infrastructure.OAuth;
using Xero.Api.Infrastructure.OAuth.Signing;
namespace Xero.Api.Example.Applications.Private
{
public class PrivateAuthenticator : IAuthenticator
{
private readonly X509Certificate2 _certificate;
public PrivateAuthenticator(string certificatePath)
:this(certificatePath, "")
{
}
public PrivateAuthenticator(string certificatePath, string certificatePassword = "")
{
_certificate = new X509Certificate2();
_certificate.Import(certificatePath, certificatePassword, X509KeyStorageFlags.MachineKeySet);
}
public PrivateAuthenticator(X509Certificate2 certificate)
{
_certificate = certificate;
}
public string GetSignature(IConsumer consumer, IUser user, Uri uri, string verb, IConsumer consumer1)
{
var token = new Token
{
ConsumerKey = consumer.ConsumerKey,
ConsumerSecret = consumer.ConsumerSecret,
TokenKey = consumer.ConsumerKey
};
return new RsaSha1Signer().CreateSignature(_certificate, token, uri, verb);
}
public X509Certificate Certificate { get { return _certificate; } }
public IToken GetToken(IConsumer consumer, IUser user)
{
return null;
}
public IUser User { get; set; }
}
}