/
CreateMemberSample.cs
55 lines (47 loc) · 1.88 KB
/
CreateMemberSample.cs
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
52
53
54
55
using System;
using System.IO;
using Tokenio.Proto.Common.AliasProtos;
using Tokenio.Security;
using TppMember = Tokenio.Tpp.Member;
namespace Tokenio.Sample.Tpp
{
public static class CreateMemberSample
{
/// <summary>
/// Creates and returns a new token member.
/// </summary>
/// <returns>a new Member instance</returns>
public static TppMember CreateMember()
{
// Create the client, which communicates with
// the Token cloud.
try
{
var key = Directory.CreateDirectory("./keys");
Tokenio.Tpp.TokenClient tokenClient = Tokenio.Tpp.TokenClient.NewBuilder()
.ConnectTo(Tokenio.TokenCluster.SANDBOX)
.WithKeyStore(new UnsecuredFileSystemKeyStore(key.FullName))
.Build();
// An alias is a "human-readable" reference to a member.
// Here, we use a random email. This works in test environments.
// but in production, TokenOS would try to verify we own the address,
// so a random address wouldn't be useful for much.
// We use a random address because otherwise, if we ran a second
// time, Token would say the alias was already taken.
Alias alias = new Alias
{
Value = TestUtil.RandomNumeric(10) + "+noverify@example.com",
Type = Alias.Types.Type.Email
};
TppMember newMember = tokenClient.CreateMemberBlocking(alias);
// let user recover member by verifying email if they lose keys
newMember.UseDefaultRecoveryRule();
return newMember;
}
catch (IOException ioe)
{
throw new ArgumentException("", ioe);
}
}
}
}