aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs
blob: 4958cb0f4c9399297a3bcfbc4f4da3a4a81fcac1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Entities;

namespace Tango.MachineStudio.Common.Authentication 
{
    /// <summary>
    /// Represents the Machine Studio user authentication provider responsible for the current logged-in user.
    /// </summary>
    public interface IAuthenticationProvider 
    {
        /// <summary>
        /// Occurs when the current logged-in user has changed.
        /// </summary>
        event EventHandler<User> CurrentUserChanged;

        /// <summary>
        /// Gets the current logged-in user.
        /// </summary>
        User CurrentUser { get; }

        /// <summary>
        /// Performs a user login by the specified email and password.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        AuthenticationLoginResult Login(String email, String password);

        /// <summary>
        /// Logs-out the current logged-in user.
        /// </summary>
        void Logout();
    }
}
an> Name = "Roy", Age = 35 }, DateTime.UtcNow.AddSeconds(2)); //Get the actual string token. String token = webToken.AccessToken; //Validate the string token using the secret. WebToken.Validate(secret, token); //Read the token payload (Expiration, Issued, Embedded Object).. var read_web_token = WebToken<TokenObject>.FromToken(token); //Validate the token again using the web token instance (Just to see if the method is working..) read_web_token.Validate(secret); //Validate the token payload reading.. Assert.AreEqual(read_web_token.Expiration.Value.ToString("hh:mm"), webToken.Expiration.Value.ToString("hh:mm")); Assert.AreEqual(read_web_token.Issued.ToString("hh:mm"), webToken.Issued.ToString("hh:mm")); Assert.AreEqual(read_web_token.Object.Name, webToken.Object.Name); Assert.AreEqual(read_web_token.Object.Age, webToken.Object.Age); //Ensure token validation fails when messing with the token string. Assert.ThrowsException<SignatureVerificationException>(() => { WebToken.Validate(secret, token.Substring(0, token.Length - 1) + "0"); }); //Wait for the token to expire... Thread.Sleep(2000); //Ensure the token validation fails with 'token expired'. Assert.ThrowsException<TokenExpiredException>(() => read_web_token.Validate(secret)); } } }