using System;
using Autofac;
using Jimu;
using ;
using ;
using ;
namespace
{
class Program
{
static void Main(string[] args)
{
IServiceHost host = null;
var builder = new ServiceHostServerBuilder(new ContainerBuilder())
.UseLog4netLogger()
.LoadServices("", "")
.UseDotNettyForTransfer("127.0.0.1", 8000)
.UseConsulForDiscovery("127.0.0.1", 8500, "JimuService", $"127.0.0.1:8000")
.UseJoseJwtForOAuth<DotNettyAddress>(new JwtAuthorizationOptions
{
SecretKey = "123456", // Key for token generation
ExpireTimeSpan = new TimeSpan(3, 0, 0, 0), // Token Valid for 3 days
ValidateLifetime = true, // Whether or not to start validating the token
ServerIp = "127.0.0.1", // Address of the host server where the token is generated
ServerPort = 8000, // Host server port for token generation
TokenEndpointPath = "api/oauth/token?username=&password=", // The route to get the token, note that the ?username=&password= suffix is fixed.
CheckCredential = new Action<JwtAuthorizationContext>(ctx =>
{
var memberService = <IAuthMemberService>();
var member = (, );
if (member == null)
{
("username or password is incorrect.", "");
}
else
{
// The JimuPayload mentioned above contains these data
("roles", ); // Adding roles to tokens
("member", (member)); // Serialize and package the entire member into a token
}
}), // Configuration items and validation logic for token generation
});
using (host = ())
{
();
while (true)
{
();
}
}
}
}
}