-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Net.Http; | ||
|
||
namespace Modio | ||
{ | ||
/// <summary> | ||
/// See <see cref="AuthClient.External(SwitchAuth)"/>. | ||
/// </summary> | ||
/// | ||
/// <seealso>https://docs.mod.io/#authenticate-via-switch</seealso> | ||
public class SwitchAuth | ||
{ | ||
/// <summary> | ||
/// The NSA ID supplied by the Nintendo Switch SDK. | ||
/// </summary> | ||
public string IdToken { get; private set; } | ||
|
||
/// <summary> | ||
/// The users email address. | ||
/// </summary> | ||
public string? Email { get; set; } | ||
|
||
/// <summary> | ||
/// Unix timestamp of date in which the returned token will expire. | ||
/// </summary> | ||
public long? ExpiredAt { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="SwitchAuth"/> with the required NSA ID. | ||
/// </summary> | ||
public SwitchAuth(string idToken) | ||
{ | ||
IdToken = idToken; | ||
} | ||
|
||
internal HttpContent ToContent() | ||
{ | ||
var parameters = new Parameters { | ||
{"id_token", IdToken}, | ||
}; | ||
if (Email is string email) | ||
{ | ||
parameters.Add("email", email); | ||
} | ||
if (ExpiredAt is long expiredAt) | ||
{ | ||
parameters.Add("date_expires", expiredAt.ToString()); | ||
} | ||
return parameters.ToContent(); | ||
} | ||
} | ||
} |