Skip to content

Commit 9cee01d

Browse files
authored
Merge pull request #76 from gnongsie/master
Adding Flex Token Verification logic
2 parents 411d232 + 227806c commit 9cee01d

File tree

7 files changed

+472
-0
lines changed

7 files changed

+472
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace CyberSource.Utilities.Flex.Exception
4+
{
5+
public abstract class FlexException : System.Exception, ISerializable
6+
{
7+
/// <summary>
8+
/// Constructs a new instance of the exception with a specified error message.
9+
/// </summary>
10+
/// <param name="message">The error message that explains the reason for the exception</param>
11+
public FlexException(string message) : base(message) { }
12+
13+
/// <summary>
14+
/// Constructs a new instance of the exception with a specified error message
15+
/// and a reference to the inner exception that is the cause of this exception.
16+
/// </summary>
17+
/// <param name="message">The error message that explains the reason for the exception</param>
18+
/// <param name="inner">The exception that is the cause of the current exception</param>
19+
public FlexException(string message, System.Exception inner) : base(message, inner) { }
20+
21+
protected FlexException(SerializationInfo serializationInfo, StreamingContext streamingContext)
22+
: base(serializationInfo, streamingContext)
23+
{
24+
}
25+
}
26+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace CyberSource.Utilities.Flex.Exception
4+
{
5+
/// <summary>
6+
/// Exception that is thrown when there is an error performing an internal SDK function.
7+
/// </summary>
8+
public class FlexInternalException : FlexException
9+
{
10+
public FlexInternalException(string message) : base(message) { }
11+
12+
public FlexInternalException(string message, System.Exception inner) : base(message, inner) { }
13+
14+
protected FlexInternalException(SerializationInfo serializationInfo, StreamingContext streamingContext)
15+
: base(serializationInfo, streamingContext)
16+
{
17+
}
18+
}
19+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace CyberSource.Utilities.Flex.Model
2+
{
3+
/// <summary>
4+
/// Represents the public RSA key in DER format.
5+
/// </summary>
6+
public class FlexDerPublicKey
7+
{
8+
/// <summary>
9+
/// Gets and sets the public key format.
10+
/// </summary>
11+
public string format { get; set; }
12+
13+
/// <summary>
14+
/// Gets and sets the algorithm with which the key is used.
15+
/// </summary>
16+
public string algorithm { get; set; }
17+
18+
/// <summary>
19+
/// Gets and sets the encoded key specification.
20+
/// </summary>
21+
public string publicKey { get; set; }
22+
23+
/// <summary>
24+
/// Default constructor. Use if you wish to set properties individually.
25+
/// </summary>
26+
public FlexDerPublicKey() { }
27+
28+
/// <summary>
29+
/// Constructs a DerPublicKey instance with the supplied format, algorithm and encoded key.
30+
/// </summary>
31+
/// <param name="format">The format</param>
32+
/// <param name="algorithm">The algorithm</param>
33+
/// <param name="publicKey">The encoded key</param>
34+
public FlexDerPublicKey(string format, string algorithm, string publicKey)
35+
{
36+
this.format = format;
37+
this.algorithm = algorithm;
38+
this.publicKey = publicKey;
39+
}
40+
}
41+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace CyberSource.Utilities.Flex.Model
2+
{
3+
public class FlexPublicKey
4+
{
5+
/// <summary>
6+
/// Gets or sets the unique ID of the key.
7+
/// </summary>
8+
public string keyId { get; set; }
9+
10+
/// <summary>
11+
/// Gets or sets the DER representation of the key.
12+
/// </summary>
13+
public FlexDerPublicKey der { get; set; }
14+
15+
/// <summary>
16+
/// Gets or sets the JSON Web Key representation of the key for use with the Web Crypto API.
17+
/// </summary>
18+
public JsonWebKey jwk { get; set; }
19+
20+
/// <summary>
21+
/// Default constructor. Use if you wish to set properties individually.
22+
/// </summary>
23+
public FlexPublicKey() { }
24+
25+
/// <summary>
26+
/// Constructs a FlexPublicKey instance with the specified ID, DER representation and JWK representation.
27+
/// </summary>
28+
/// <param name="keyId">The ID</param>
29+
/// <param name="der">The DER representation</param>
30+
/// <param name="jwk">The JWK representation</param>
31+
public FlexPublicKey(string keyId, FlexDerPublicKey der, JsonWebKey jwk)
32+
{
33+
this.keyId = keyId;
34+
this.der = der;
35+
this.jwk = jwk;
36+
}
37+
38+
public override string ToString()
39+
{
40+
return System.String.Format("FlexPublicKey[keyId={0}]", keyId);
41+
}
42+
}
43+
}

Utilities/Flex/Model/FlexToken.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Collections.Generic;
2+
3+
namespace CyberSource.Utilities.Flex.Model
4+
{
5+
/// <summary>
6+
/// Represents the Flex API token response.
7+
/// </summary>
8+
public class FlexToken
9+
{
10+
/// <summary>
11+
/// Gets or sets the ID of the key associated with the token.
12+
/// </summary>
13+
public string keyId { get; set; }
14+
15+
/// <summary>
16+
/// Gets or sets the generated token. The token replaces card data and is used as the Subscription ID in the CyberSource Simple Order API or SCMP API.
17+
/// </summary>
18+
public string token { get; set; }
19+
20+
/// <summary>
21+
/// Gets or sets the masked card number.
22+
/// </summary>
23+
public string maskedPan { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets the card type.
27+
/// </summary>
28+
public string cardType { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the UTC date and time in milliseconds at which the signature was generated.
32+
/// </summary>
33+
public long timestamp { get; set; }
34+
35+
/// <summary>
36+
/// Gets or sets the list of follow-on services with which the token may be used.
37+
/// </summary>
38+
public IDictionary<string, object> discoverableServices { get; set; }
39+
40+
/// <summary>
41+
/// Gets or sets which fields from the response make up the data that is used when verifying the response signature.
42+
/// </summary>
43+
public string signedFields { get; set; }
44+
45+
/// <summary>
46+
/// Gets or sets the Flex-generated digital signature. To ensure the values have not been tampered with while passing through the client, verify the signature server-side using the associated Flex API public key.
47+
/// </summary>
48+
public string signature { get; set; }
49+
50+
/// <summary>
51+
/// Gets or sets the embedded object(s).
52+
/// </summary>
53+
public IDictionary<string, object> _embedded { get; set; }
54+
55+
/// <summary>
56+
/// Constructs a FlexToken instance.
57+
/// </summary>
58+
public FlexToken() { }
59+
}
60+
}

Utilities/Flex/Model/JsonWebKey.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
namespace CyberSource.Utilities.Flex.Model
2+
{
3+
/// <summary>
4+
/// Represents a JSON Web Key for use with the Web Crypto API.
5+
/// </summary>
6+
public class JsonWebKey
7+
{
8+
/// <summary>
9+
/// Gets or sets the key type.
10+
/// </summary>
11+
public string kty { get; set; }
12+
13+
/// <summary>
14+
/// Gets or sets the key use.
15+
/// </summary>
16+
public string use { get; set; }
17+
18+
/// <summary>
19+
/// Gets or sets the key ID.
20+
/// </summary>
21+
public string kid { get; set; }
22+
23+
/// <summary>
24+
/// Gets or sets the modulus.
25+
/// </summary>
26+
public string n { get; set; }
27+
28+
/// <summary>
29+
/// Gets or sets the exponent.
30+
/// </summary>
31+
public string e { get; set; }
32+
33+
/// <summary>
34+
/// Default constructor. Use if you wish to set properties individually.
35+
/// </summary>
36+
public JsonWebKey() { }
37+
38+
/// <summary>
39+
/// Constructs a JsonWebKey instance with the specified key type, key use, key ID, modulus and exponent.
40+
/// </summary>
41+
/// <param name="keyType">The key type</param>
42+
/// <param name="keyUse">The key use</param>
43+
/// <param name="keyId">The key ID</param>
44+
/// <param name="modulus">The modulus</param>
45+
/// <param name="exponent">The exponent</param>
46+
public JsonWebKey(string keyType, string keyUse, string keyId, string modulus, string exponent)
47+
{
48+
this.kty = keyType;
49+
this.use = keyUse;
50+
this.kid = keyId;
51+
this.n = modulus;
52+
this.e = exponent;
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)