diff --git a/WordPressPCL/Client/Auth.cs b/WordPressPCL/Client/Auth.cs index 2ac1929..61c0855 100644 --- a/WordPressPCL/Client/Auth.cs +++ b/WordPressPCL/Client/Auth.cs @@ -100,6 +100,10 @@ public async Task RequestJWTokenAsync(string username, string password) { _httpHelper.HttpResponsePreProcessing = null; _httpHelper.JWToken = jwtResponse?.Data?.Token; break; + case JWTPlugin.JWTSimpleJwtLogin: + var (jwtSimpleJwtLogin, _) = await _httpHelper.PostRequestAsync("?rest_route=/simple-jwt-login/v1/auth", formContent, isAuthRequired: false, ignoreDefaultPath: true).ConfigureAwait(false); + _httpHelper.JWToken = jwtSimpleJwtLogin?.Data.Token; + break; default: throw new WPException("Invalid JWT Plugin"); } @@ -134,6 +138,9 @@ public async Task IsValidJWTokenAsync() { var (jwtResponse, _) = await _httpHelper.PostRequestAsync(route, null, isAuthRequired: true, ignoreDefaultPath: true).ConfigureAwait(false); _httpHelper.HttpResponsePreProcessing = null; return jwtResponse.Success; + case JWTPlugin.JWTSimpleJwtLogin: + var (jwtSimpleJwtLogin, _) = await _httpHelper.PostRequestAsync("?rest_route=/simple-jwt-login/v1/auth/validate", null, isAuthRequired: true, ignoreDefaultPath: true).ConfigureAwait(false); + return jwtSimpleJwtLogin.Success; default: throw new WPException("Invalid JWT Plugin"); } diff --git a/WordPressPCL/Models/JWTPlugin.cs b/WordPressPCL/Models/JWTPlugin.cs index 301ff96..f84417b 100644 --- a/WordPressPCL/Models/JWTPlugin.cs +++ b/WordPressPCL/Models/JWTPlugin.cs @@ -1,4 +1,4 @@ -namespace WordPressPCL.Models { +namespace WordPressPCL.Models { /// /// JWT Plugins supported @@ -14,7 +14,13 @@ public enum JWTPlugin { /// JWT Auth – WordPress JSON Web Token Authentication plugin /// Author - Useful Team /// - JWTAuthByUsefulTeam - + JWTAuthByUsefulTeam, + /// + /// simple-jwt-login – WordPress JSON Web Token Authentication plugin + /// https://wordpress.org/plugins/simple-jwt-login/ + /// Author - Nicu Micle + /// + JWTSimpleJwtLogin + } -} \ No newline at end of file +} diff --git a/WordPressPCL/Models/JWTSimpleJwtLogin.cs b/WordPressPCL/Models/JWTSimpleJwtLogin.cs new file mode 100644 index 0000000..6aa1fbf --- /dev/null +++ b/WordPressPCL/Models/JWTSimpleJwtLogin.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; +using Newtonsoft.Json; + +namespace WordPressPCL.Models +{ + /// + /// Response class for the JWT Plugin + /// + public class JWTSimpleJwtLogin + { + /// + /// Indicates if the call was successful + /// + [JsonProperty("success")] + public bool Success { get; set; } + + /// + /// The response message + /// + [JsonProperty("message")] + [DefaultValue(null)] + public string Message { get; set; } + + /// + /// The JWT Content + /// + [JsonProperty("data")] + [DefaultValue(null)] + public JWTSimpleJwtLoginData Data { get; set; } + } + + public class JWTSimpleJwtLoginData + { + /// + /// JWT Token + /// + [JsonProperty("jwt")] + public string Token { get; set; } + } +} diff --git a/WordPressPCL/Models/JWTSimpleJwtLoginResponse.cs b/WordPressPCL/Models/JWTSimpleJwtLoginResponse.cs new file mode 100644 index 0000000..d9b3844 --- /dev/null +++ b/WordPressPCL/Models/JWTSimpleJwtLoginResponse.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; +using Newtonsoft.Json; + +namespace WordPressPCL.Models +{ + public class JWTSimpleJwtLoginResponse + { + [JsonProperty("success")] + public bool Success { get; set; } + + [JsonProperty("data")] + [DefaultValue(null)] + public JWTSimpleJwtLoginResponseData Data { get; set; } + } + + public class JWTSimpleJwtLoginResponseData + { + [JsonProperty("user")] + public JWTSimpleJwtLoginResponseDataUser User { get; set; } + + [JsonProperty("roles")] + public List Roles { get; set; } + + [JsonProperty("jwt")] + public List Jwt { get; set; } + } + + public class JWTSimpleJwtLoginResponseDataJwt + { + [JsonProperty("token")] + public string Token { get; set; } + + [JsonProperty("header")] + public JWTSimpleJwtLoginResponseDataJwtHeader Header { get; set; } + + [JsonProperty("payload")] + public JWTSimpleJwtLoginResponseDataJwtPayload Payload { get; set; } + + [JsonProperty("expire_in")] + public int ExpireIn { get; set; } + } + + public class JWTSimpleJwtLoginResponseDataJwtHeader + { + [JsonProperty("typ")] + public string Typ { get; set; } + + [JsonProperty("alg")] + public string Alg { get; set; } + } + + public class JWTSimpleJwtLoginResponseDataJwtPayload + { + [JsonProperty("iat")] + public int Iat { get; set; } + + [JsonProperty("exp")] + public int Exp { get; set; } + + [JsonProperty("email")] + public string Email { get; set; } + + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("site")] + public string Site { get; set; } + + [JsonProperty("username")] + public string Username { get; set; } + } + + public class JWTSimpleJwtLoginResponseDataUser + { + [JsonProperty("ID")] + public string Id { get; set; } + + [JsonProperty("user_login")] + public string UserLogin { get; set; } + + [JsonProperty("user_nicename")] + public string UserNicename { get; set; } + + [JsonProperty("user_email")] + public string UserEmail { get; set; } + + [JsonProperty("user_url")] + public string UserUrl { get; set; } + + [JsonProperty("user_registered")] + public string UserRegistered { get; set; } + + [JsonProperty("user_activation_key")] + public string UserActivationKey { get; set; } + + [JsonProperty("user_status")] + public string UserStatus { get; set; } + + [JsonProperty("display_name")] + public string DisplayName { get; set; } + } +}