Skip to content

Commit aca9af9

Browse files
ci-stytchStytch Codegen Bot
andauthored
Add DFP Email Risk endpoint (#55)
Co-authored-by: Stytch Codegen Bot <support@stytch.com>
1 parent 37fa202 commit aca9af9

File tree

5 files changed

+211
-1
lines changed

5 files changed

+211
-1
lines changed

Stytch.net/Clients/consumer/Fraud.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ public class Fraud
2525
public readonly FraudFingerprint Fingerprint;
2626
public readonly FraudRules Rules;
2727
public readonly FraudVerdictReasons VerdictReasons;
28+
public readonly FraudEmail Email;
2829
public Fraud(HttpClient client, ClientConfig config)
2930
{
3031
_httpClient = client;
3132
_config = config;
3233
Fingerprint = new FraudFingerprint(_httpClient, _config);
3334
Rules = new FraudRules(_httpClient, _config);
3435
VerdictReasons = new FraudVerdictReasons(_httpClient, _config);
36+
Email = new FraudEmail(_httpClient, _config);
3537
}
3638

3739

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// !!!
2+
// WARNING: This file is autogenerated
3+
// Only modify code within MANUAL() sections
4+
// or your changes may be overwritten later!
5+
// !!!
6+
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Net.Http;
10+
using System.Text;
11+
using System.Threading.Tasks;
12+
using Newtonsoft.Json;
13+
using Stytch.net.Exceptions;
14+
using Stytch.net.Models;
15+
16+
17+
18+
19+
namespace Stytch.net.Clients.Consumer
20+
{
21+
public class FraudEmail
22+
{
23+
private readonly ClientConfig _config;
24+
private readonly HttpClient _httpClient;
25+
public FraudEmail(HttpClient client, ClientConfig config)
26+
{
27+
_httpClient = client;
28+
_config = config;
29+
}
30+
31+
/// <summary>
32+
/// Get risk information for a specific email address.
33+
/// The response will contain a recommended action (`ALLOW`, `BLOCK`, or `CHALLENGE`) and a more granular
34+
/// `risk_score`.
35+
/// You can also check the `address_information` and `domain_information` fields for more information about
36+
/// the email address and email domain.
37+
///
38+
/// This feature is in beta. Reach out to us
39+
/// [here](mailto:fraud-team@stytch.com?subject=Email_Intelligence_Early_Access) if you'd like to request
40+
/// early access.
41+
/// </summary>
42+
public async Task<FraudEmailRiskResponse> Risk(
43+
FraudEmailRiskRequest request
44+
)
45+
{
46+
var method = HttpMethod.Post;
47+
var uriBuilder = new UriBuilder(_httpClient.BaseAddress)
48+
{
49+
Path = $"/v1/email/risk"
50+
};
51+
52+
var httpReq = new HttpRequestMessage(method, uriBuilder.ToString());
53+
var jsonSettings = new JsonSerializerSettings
54+
{
55+
NullValueHandling = NullValueHandling.Ignore
56+
};
57+
var jsonBody = JsonConvert.SerializeObject(request, jsonSettings);
58+
var content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
59+
httpReq.Content = content;
60+
61+
var response = await _httpClient.SendAsync(httpReq);
62+
var responseBody = await response.Content.ReadAsStringAsync();
63+
64+
if (response.IsSuccessStatusCode)
65+
{
66+
return JsonConvert.DeserializeObject<FraudEmailRiskResponse>(responseBody);
67+
}
68+
try
69+
{
70+
var apiException = JsonConvert.DeserializeObject<StytchApiException>(responseBody);
71+
throw apiException;
72+
}
73+
catch (JsonException)
74+
{
75+
throw new StytchNetworkException($"Unexpected error occurred: {responseBody}", response);
76+
}
77+
}
78+
79+
}
80+
81+
}

Stytch.net/Models/Consumer/Fraud.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,35 @@ public class ASNProperties
3030
[JsonProperty("network")]
3131
public string Network { get; set; }
3232
}
33+
public class AddressInformation
34+
{
35+
/// <summary>
36+
/// Whether email sent to this address is known to have bounced previously.
37+
/// </summary>
38+
[JsonProperty("has_known_bounces")]
39+
public bool HasKnownBounces { get; set; }
40+
/// <summary>
41+
/// Whether this email address is valid.
42+
/// </summary>
43+
[JsonProperty("has_valid_syntax")]
44+
public bool HasValidSyntax { get; set; }
45+
/// <summary>
46+
/// Whether the local part of the email appears to be a role or group, rather than an individual end user.
47+
/// </summary>
48+
[JsonProperty("is_suspected_role_address")]
49+
public bool IsSuspectedRoleAddress { get; set; }
50+
/// <summary>
51+
/// The normalized email address after removing '.' characters and any characters after a '+'.
52+
/// </summary>
53+
[JsonProperty("normalized_email")]
54+
public string NormalizedEmail { get; set; }
55+
/// <summary>
56+
/// The number of '.' and '+' characters in the email address. A higher tumbling count indicates a higher
57+
/// potential for fraud.
58+
/// </summary>
59+
[JsonProperty("tumbling_character_count")]
60+
public int TumblingCharacterCount { get; set; }
61+
}
3362
public class BrowserProperties
3463
{
3564
/// <summary>
@@ -38,6 +67,19 @@ public class BrowserProperties
3867
[JsonProperty("user_agent")]
3968
public string UserAgent { get; set; }
4069
}
70+
public class DomainInformation
71+
{
72+
/// <summary>
73+
/// Whether the email has appropriate DNS records to deliver a message.
74+
/// </summary>
75+
[JsonProperty("has_mx_or_a_record")]
76+
public bool HasMXOrARecord { get; set; }
77+
/// <summary>
78+
/// Whether the email domain is known to be disposable.
79+
/// </summary>
80+
[JsonProperty("is_disposable_domain")]
81+
public bool IsDisposableDomain { get; set; }
82+
}
4183
public class Fingerprints
4284
{
4385
/// <summary>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// !!!
2+
// WARNING: This file is autogenerated
3+
// Only modify code within MANUAL() sections
4+
// or your changes may be overwritten later!
5+
// !!!
6+
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Runtime.Serialization;
10+
using Newtonsoft.Json;
11+
using Newtonsoft.Json.Converters;
12+
13+
namespace Stytch.net.Models
14+
{
15+
/// <summary>
16+
/// Request type for <see cref="Stytch.net.Clients.Consumer.Fraud.Email.Risk"/>..
17+
/// </summary>
18+
public class FraudEmailRiskRequest
19+
{
20+
/// <summary>
21+
/// The email address to check.
22+
/// </summary>
23+
[JsonProperty("email_address")]
24+
public string EmailAddress { get; set; }
25+
public FraudEmailRiskRequest(string emailAddress)
26+
{
27+
this.EmailAddress = emailAddress;
28+
}
29+
}
30+
/// <summary>
31+
/// Response type for <see cref="Stytch.net.Clients.Consumer.Fraud.Email.Risk"/>..
32+
/// </summary>
33+
public class FraudEmailRiskResponse
34+
{
35+
/// <summary>
36+
/// Globally unique UUID that is returned with every API call. This value is important to log for debugging
37+
/// purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
38+
/// </summary>
39+
[JsonProperty("request_id")]
40+
public string RequestId { get; set; }
41+
/// <summary>
42+
/// Information about the email address.
43+
/// </summary>
44+
[JsonProperty("address_information")]
45+
public AddressInformation AddressInformation { get; set; }
46+
/// <summary>
47+
/// Information about the email domain.
48+
/// </summary>
49+
[JsonProperty("domain_information")]
50+
public DomainInformation DomainInformation { get; set; }
51+
/// <summary>
52+
/// The suggested action based on the attributes of the email address. The available actions are:
53+
/// * `ALLOW` - This email is most likely safe to send to and not fraudulent.
54+
/// * `BLOCK` - This email is invalid or exhibits signs of fraud. We recommend blocking the end user.
55+
/// * `CHALLENGE` - This email has some potentially fraudulent attributes. We recommend increased friction
56+
/// such as 2FA or other forms of extended user verification before allowing the privileged action to
57+
/// proceed.
58+
///
59+
/// </summary>
60+
[JsonProperty("action")]
61+
public RiskResponseAction Action { get; set; }
62+
/// <summary>
63+
/// A score from 0 to 100 indicating how risky the email is. 100 is the most risky.
64+
/// </summary>
65+
[JsonProperty("risk_score")]
66+
public int RiskScore { get; set; }
67+
/// <summary>
68+
/// The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g.
69+
/// 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
70+
/// </summary>
71+
[JsonProperty("status_code")]
72+
public int StatusCode { get; set; }
73+
}
74+
75+
[JsonConverter(typeof(StringEnumConverter))]
76+
public enum RiskResponseAction
77+
{
78+
[EnumMember(Value = "ALLOW")]
79+
ALLOW,
80+
[EnumMember(Value = "CHALLENGE")]
81+
CHALLENGE,
82+
[EnumMember(Value = "BLOCK")]
83+
BLOCK,
84+
}
85+
}

Stytch.net/Stytch.net.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageId>Stytch.net</PackageId>
99
<AssemblyTitle>Stytch.net</AssemblyTitle>
1010
<AssemblyName>Stytch.net</AssemblyName>
11-
<Version>3.0.0</Version>
11+
<Version>3.1.0</Version>
1212
<Author>Stytch</Author>
1313
<Product>Stytch</Product>
1414
<PackageProjectUrl>https://github.com/stytchauth/stytch-dotnet</PackageProjectUrl>

0 commit comments

Comments
 (0)