public JsonResult GetToken(int clientId, string userName, string password) { try { log.Info("GetToken method called for client id: " + clientId + " and username: "******"true", message = "Authentication successful", access_token = encodedJwt, expires_in_seconds = (int)TimeSpan.FromMinutes(60).TotalSeconds }; log.Info("Token generated for client id:" + clientId + " and username: "******"false", message = "Not authenticated", access_token = "", expires_in_seconds = 0 }; log.Info("Client not authenticated client id:" + clientId + " and username: "******"Token generation failed for client id:" + clientId + " and username: "******"false", message = "Some error occured", access_token = "", expires_in_seconds = 0 }; return(Json(responseJson)); } }
public static bool ValidateToken(string token, string serviceName, out int serviceId) { serviceId = 0; var simplePrinciple = GetPrincipal(token); var identity = simplePrinciple?.Identity as ClaimsIdentity; if (identity == null) { return(false); } if (!identity.IsAuthenticated) { return(false); } //var usernameClaim = identity.FindFirst(ClaimTypes.Name); //username = usernameClaim?.Value; var clientUserIdClaim = identity.FindFirst("ClientUserId"); string clientUserIdString = clientUserIdClaim?.Value; if (string.IsNullOrEmpty(clientUserIdString)) { return(false); } int clientUserId = Convert.ToInt32(clientUserIdString); bool userServicePermission = ClientUserDataProvider.VerifyUserService(clientUserId, serviceName, out serviceId); if (userServicePermission) { return(true); } else { return(false); } }