//private static Timer _timer; // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddCors(); services .AddSignalR(options => { options.EnableDetailedErrors = true; }) .AddMessagePackProtocol(); services.AddMvcCore() .AddNewtonsoftJson() .AddAuthorization(); services.AddIdentityServer( options => { options.Events.RaiseErrorEvents = true; options.Events.RaiseSuccessEvents = true; options.Events.RaiseFailureEvents = true; options.Events.RaiseInformationEvents = true; }) .AddInMemoryApiResources(ISConfig.GetApiResources()) .AddInMemoryApiScopes(ISConfig.GetApiScopes()) .AddTestUsers(ISConfig.GetUsers()) .AddInMemoryClients(ISConfig.GetClients()) //.AddSigningCredential(Cert.Get("theCert.pfx", "somePassword")) .AddDeveloperSigningCredential(); services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) .AddIdentityServerAuthentication(options => { options.Authority = "https://localhost:5001/"; options.RequireHttpsMetadata = true; options.ApiName = "shortlivedchat"; options.TokenRetriever = new Func <HttpRequest, string>(req => { var fromAuthorizationHeader = TokenRetrieval.FromAuthorizationHeader(); var fromQueryString = TokenRetrieval.FromQueryString(); return(fromAuthorizationHeader(req) ?? fromQueryString(req)); }); IdentityModelEventSource.ShowPII = true; }); services.AddSingleton <GroupsManager>(); }
//TODO:find a better way to get the user's name. private string GetUserName() { var user = ISConfig.GetUsers().FirstOrDefault(x => x.SubjectId == Context.User.GetDisplayName()); return(user.Username); }