mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
1
This commit is contained in:
parent
3488bd6ae7
commit
5cfe7dad78
|
@ -21,7 +21,7 @@
|
|||
"FastTunnel": {
|
||||
"Server": {
|
||||
// [必选] 服务端ip/域名(来自服务端配置文件的urls参数)
|
||||
"ServerAddr": "suidao.bx.com.cn",
|
||||
"ServerAddr": "127.0.0.1",
|
||||
// [必选] 服务端监听的通信端口(来自服务端配置文件的urls参数)
|
||||
"ServerPort": 1270
|
||||
},
|
||||
|
|
|
@ -4,16 +4,23 @@
|
|||
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
|
||||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using FastTunnel.Api.Filters;
|
||||
using FastTunnel.Core.Config;
|
||||
using FastTunnel.Core.Extensions;
|
||||
using FastTunnel.Server.Models;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
|
@ -64,6 +71,37 @@ public class Program
|
|||
builder.Services.AddFastTunnelServer(builder.Configuration.GetSection("FastTunnel"));
|
||||
// -------------------FastTunnel STEP1 END-------------------
|
||||
|
||||
var Configuration = builder.Configuration;
|
||||
var apioptions = Configuration.GetSection("FastTunnel").Get<DefaultServerConfig>();
|
||||
|
||||
builder.Services.AddAuthentication("Bearer").AddJwtBearer(delegate (JwtBearerOptions options)
|
||||
{
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = false,
|
||||
ValidateAudience = false,
|
||||
ValidateLifetime = true,
|
||||
ClockSkew = TimeSpan.FromSeconds(apioptions.Api.JWT.ClockSkew),
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidAudience = apioptions.Api.JWT.ValidAudience,
|
||||
ValidIssuer = apioptions.Api.JWT.ValidIssuer,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(apioptions.Api.JWT.IssuerSigningKey))
|
||||
};
|
||||
options.Events = new JwtBearerEvents
|
||||
{
|
||||
OnChallenge = async delegate (JwtBearerChallengeContext context)
|
||||
{
|
||||
context.HandleResponse();
|
||||
context.Response.ContentType = "application/json;charset=utf-8";
|
||||
await context.Response.WriteAsJsonAsync(new
|
||||
{
|
||||
code = -1,
|
||||
message = context.Error ?? "未登录"
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
builder.Host.UseWindowsService();
|
||||
|
||||
var app = builder.Build();
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
// 可选,当不为空时,客户端也必须携带Tokens中的任意一个token,否则拒绝登录。
|
||||
"Tokens": [ "TOKEN_FOR_CLIENT_AUTHENTICATION" ],
|
||||
|
||||
/**
|
||||
* 访问api接口的JWT配置
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user