Version 1.0.5-rc22
This commit is contained in:
@ -378,6 +378,18 @@ namespace Yavsc.Authentication
|
||||
public async Task<IDictionary<string, string>> RequestAccessTokenAsync(IDictionary<string, string> queryValues)
|
||||
{
|
||||
StringBuilder postData = new StringBuilder();
|
||||
if (!queryValues.ContainsKey("client_id"))
|
||||
{
|
||||
postData.Append("client_id="+Uri.EscapeDataString($"{this.clientId}")+"&");
|
||||
}
|
||||
if (!queryValues.ContainsKey("client_secret"))
|
||||
{
|
||||
postData.Append("client_secret="+Uri.EscapeDataString($"{this.clientSecret}")+"&");
|
||||
}
|
||||
if (!queryValues.ContainsKey("scope"))
|
||||
{
|
||||
postData.Append("scope="+Uri.EscapeDataString($"{this.scope}")+"&");
|
||||
}
|
||||
foreach (string key in queryValues.Keys)
|
||||
{
|
||||
postData.Append($"{key}="+Uri.EscapeDataString($"{queryValues[key]}")+"&");
|
||||
|
@ -67,8 +67,6 @@ namespace Yavsc
|
||||
var val = JsonConvert.SerializeObject(prop.Value);
|
||||
logger.LogInformation( $"#Property {prop.Key}: {val}" );
|
||||
}
|
||||
|
||||
var bot = await this._usermanager.GetUserByNameAsync(botName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,18 @@
|
||||
{
|
||||
"Site": {
|
||||
"Authority": "dev.pschneider.fr",
|
||||
"Title": "Yavsc dev",
|
||||
"Slogan": "Yavsc : WIP.",
|
||||
"Banner": "/images/yavsc.png",
|
||||
"HomeViewName": "Home",
|
||||
"FavIcon": "/favicon.ico",
|
||||
"Icon": "/images/yavsc.png"
|
||||
"ConnectionSettings" : {
|
||||
"Site": {
|
||||
"Authority": "oauth.server-example.com",
|
||||
"Title": "[Site title]",
|
||||
"Slogan": "[Site Slogan]",
|
||||
"Banner": "/images/[bannerAsset]",
|
||||
"HomeViewName": "Home",
|
||||
"FavIcon": "/favicon.ico",
|
||||
"Icon": "/images/[Site Icon]"
|
||||
},
|
||||
"ServerApiKey": {
|
||||
"ClientId": "[OAuth2NativeClientId]",
|
||||
"ClientSecret": "[OAuth2ClientSecret]"
|
||||
}
|
||||
},
|
||||
"Logging": {
|
||||
"IncludeScopes": true,
|
||||
@ -18,7 +24,7 @@
|
||||
},
|
||||
"Data": {
|
||||
"DefaultConnection": {
|
||||
"ConnectionString": "Server=localhost;Port=5432;Database=YavscDev;Username=yavscdev;Password=admin;"
|
||||
"ConnectionString": "[sbConStr]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,15 +45,15 @@
|
||||
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4",
|
||||
"Newtonsoft.Json": "9.0.1",
|
||||
"Yavsc": {
|
||||
"version": "1.0.5-rc21-beta9",
|
||||
"version": "1.0.5-rc22",
|
||||
"target": "package"
|
||||
},
|
||||
"Yavsc.Abstract": {
|
||||
"version": "1.0.5-rc21-beta9",
|
||||
"version": "1.0.5-rc22",
|
||||
"target": "package"
|
||||
},
|
||||
"Yavsc.Server": {
|
||||
"version": "1.0.5-rc21-beta9",
|
||||
"version": "1.0.5-rc22",
|
||||
"target": "package"
|
||||
},
|
||||
"Yavsc.Lib.Portable": "1.0.2"
|
||||
|
56
cli/src/ConnectionSettings.cs
Normal file
56
cli/src/ConnectionSettings.cs
Normal file
@ -0,0 +1,56 @@
|
||||
namespace cli
|
||||
{
|
||||
using Yavsc.Abstract.Identity;
|
||||
using Yavsc;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Newtonsoft.Json;
|
||||
using Yavsc.Authentication;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class ConnectionSettings
|
||||
{
|
||||
public TokenInfo UserToken { get; set; }
|
||||
public SiteSettings Site { get; set; }
|
||||
public OAuth2AppSettings ServerApiKey { get; set; }
|
||||
public string SiteAccessSheme { get; set; } = "http";
|
||||
public string Scope { get; set; } = "profile";
|
||||
|
||||
[NotMapped]
|
||||
[JsonIgnore]
|
||||
public string AuthorizeUrl {get {
|
||||
return $"{SiteAccessSheme}://{Site.Authority}/authorize";
|
||||
} }
|
||||
|
||||
[NotMapped]
|
||||
[JsonIgnore]
|
||||
public string RedirectUrl {get {
|
||||
return $"{SiteAccessSheme}://{Site.Authority}/oauth/success";
|
||||
} }
|
||||
|
||||
[NotMapped]
|
||||
[JsonIgnore]
|
||||
public string AccessTokenUrl {get {
|
||||
return $"{SiteAccessSheme}://{Site.Authority}/token";
|
||||
} }
|
||||
|
||||
public async Task InitUserTokenFromLoginPass(string login, string pass)
|
||||
{
|
||||
var oauthor =new OAuthenticator( ServerApiKey.ClientId, ServerApiKey.ClientSecret, Scope,
|
||||
new Uri( AuthorizeUrl) , new Uri(RedirectUrl) , new Uri(AccessTokenUrl));
|
||||
var query = new Dictionary<string,string>();
|
||||
query["username"]=login;
|
||||
query["password"]=pass;
|
||||
query["grant_type"]="password";
|
||||
var result = await oauthor.RequestAccessTokenAsync(query);
|
||||
UserToken = new TokenInfo {
|
||||
AccessToken = result["access_token"],
|
||||
RefreshToken = result["refresh_token"],
|
||||
Received = DateTime.Now,
|
||||
ExpiresIn = int.Parse(result["expires_in"]),
|
||||
TokenType = result["token_type"]
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@ using Microsoft.Extensions.Logging;
|
||||
// using Microsoft.AspNet.Diagnostics;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using cli.Services;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using System;
|
||||
|
||||
namespace cli
|
||||
{
|
||||
@ -11,20 +13,59 @@ namespace cli
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var host = new WebHostBuilder();
|
||||
|
||||
var hostengnine = host
|
||||
.UseEnvironment("Development")
|
||||
.UseServer("cli")
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
CommandArgument sendMailCommandArg=null;
|
||||
CommandLineApplication sendMailCommand=null;
|
||||
CommandOption sendHelpOption=null;
|
||||
CommandOption rootCommandHelpOption = null;
|
||||
|
||||
CommandLineApplication cliapp = new CommandLineApplication(false);
|
||||
cliapp.Name = "cli";
|
||||
cliapp.FullName = "Yavsc command line interface";
|
||||
cliapp.Description = "Dnx console for yavsc server side";
|
||||
cliapp.ShortVersionGetter = () => "v1.0";
|
||||
cliapp.LongVersionGetter = () => "version 1.0 (stable)";
|
||||
rootCommandHelpOption = cliapp.HelpOption("-? | -h | --help");
|
||||
|
||||
sendMailCommand = cliapp.Command("send",
|
||||
(target) => {
|
||||
target.FullName="Send email";
|
||||
target.Description="Sends emails using given template";
|
||||
sendHelpOption = target.HelpOption("-? | -h | --help");
|
||||
sendMailCommandArg = target.Argument(
|
||||
"class",
|
||||
"class name of mailling to execute (actually, only 'monthly') .",
|
||||
multipleValues: true);
|
||||
}, false);
|
||||
|
||||
var app = hostengnine.Start();
|
||||
var mailer = app.Services.GetService<EMailer>();
|
||||
var loggerFactory = app.Services.GetService<ILoggerFactory>();
|
||||
var logger = loggerFactory.CreateLogger<Program>();
|
||||
mailer.SendMonthlyEmail(1,"UserOrientedTemplate");
|
||||
logger.LogInformation("Finished");
|
||||
sendMailCommand.OnExecute(() =>
|
||||
{
|
||||
if (sendMailCommandArg.Value == "monthly")
|
||||
{
|
||||
var host = new WebHostBuilder();
|
||||
var hostengnine = host.UseEnvironment("Development")
|
||||
.UseServer("cli")
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
var app = hostengnine.Start();
|
||||
var mailer = app.Services.GetService<EMailer>();
|
||||
var loggerFactory = app.Services.GetService<ILoggerFactory>();
|
||||
var logger = loggerFactory.CreateLogger<Program>();
|
||||
logger.LogInformation("Starting emailling");
|
||||
mailer.SendMonthlyEmail(1, "UserOrientedTemplate");
|
||||
logger.LogInformation("Finished emailling");
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMailCommand.ShowHelp();
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
cliapp.Execute(args);
|
||||
|
||||
if (args.Length==0 || cliapp.RemainingArguments.Count>0)
|
||||
cliapp.ShowHint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor;
|
||||
|
||||
namespace cli
|
||||
{
|
||||
|
@ -3,7 +3,6 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Hosting.Server;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc.Server
|
||||
{
|
||||
|
7
dnx.mk
7
dnx.mk
@ -62,14 +62,17 @@ bin/output:
|
||||
bin/output/wwwroot/version: bin/output
|
||||
@git log -1 --pretty=format:%h > bin/output/wwwroot/version
|
||||
|
||||
pack: $(NUGETSOURCE)/$(PKGFILENAME)
|
||||
|
||||
$(NUGETSOURCE)/$(PKGFILENAME): $(BINTARGETPATH) $(SOLUTIONDIR)/rc-num.txt
|
||||
ifeq ($(git_status),0)
|
||||
nuget pack $(PRJNAME).nuspec -Version $(VERSION) -Properties config=$(CONFIGURATION) -OutputDirectory $(NUGETSOURCE)
|
||||
nuget pack $(PRJNAME).nuspec -Version $(VERSION) -Properties config=$(CONFIGURATION) -OutputDirectory bin
|
||||
else
|
||||
$(error Please, commit your changes before publishing your NuGet packages)
|
||||
endif
|
||||
|
||||
deploy-pkg: $(NUGETSOURCE)/$(PKGFILENAME)
|
||||
deploy-pkg: pack
|
||||
@mv bin/$(PKGFILENAME) $(NUGETSOURCE)
|
||||
|
||||
.PHONY: rc-num.txt-check $(BINTARGETPATH)
|
||||
|
||||
|
@ -1 +1 @@
|
||||
21-beta9
|
||||
22
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions;
|
||||
using Yavsc.Lib;
|
||||
using Yavsc.Services;
|
||||
using Yavsc;
|
||||
@ -17,14 +18,31 @@ namespace test
|
||||
.UseServer("test")
|
||||
.UseStartup<test.Startup>()
|
||||
.Build();
|
||||
|
||||
|
||||
var app = hostengnine.Start();
|
||||
var sender = app.Services.GetService(typeof(IEmailSender)) as IEmailSender;
|
||||
var mailer = app.Services.GetService(typeof(EMailer)) as EMailer;
|
||||
var loggerFactory = app.Services.GetService(typeof(ILoggerFactory)) as ILoggerFactory;
|
||||
ILogger logger = loggerFactory.CreateLogger<Program>() ;
|
||||
mailer.SendMonthlyEmail(1,"UserOrientedTemplate");
|
||||
logger.LogInformation("Finished");
|
||||
|
||||
CommandArgument opName = new CommandArgument()
|
||||
{
|
||||
Name = "command",
|
||||
Description = "command to invoke ('monthlyTasks')",
|
||||
MultipleValues = false
|
||||
};
|
||||
|
||||
if (opName.Value == "monthlyTasks") {
|
||||
CommandOption opMailId = new CommandOption("m", OptionTypes.SingleValue )
|
||||
{
|
||||
LongName = "mail-id",
|
||||
Description = "UserOrientedTemplate template id to use ('1')",
|
||||
};
|
||||
|
||||
var sender = app.Services.GetService(typeof(IEmailSender)) as IEmailSender;
|
||||
var mailer = app.Services.GetService(typeof(EMailer)) as EMailer;
|
||||
var loggerFactory = app.Services.GetService(typeof(ILoggerFactory)) as ILoggerFactory;
|
||||
ILogger logger = loggerFactory.CreateLogger<Program>() ;
|
||||
|
||||
mailer.SendMonthlyEmail(opMailId.Value,"UserOrientedTemplate");
|
||||
logger.LogInformation("Finished");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,15 +49,11 @@ namespace test
|
||||
)
|
||||
{
|
||||
try {
|
||||
var r = new Uri(redirectUrl);
|
||||
var oauthor =new OAuthenticator( clientId, clientSecret, scope,
|
||||
new Uri( authorizeUrl) , new Uri(redirectUrl) , new Uri(accessTokenUrl));
|
||||
var query = new Dictionary<string,string>();
|
||||
query[Parameters.Username]=login;
|
||||
query[Parameters.Password]=pass;
|
||||
query[Parameters.ClientId]=clientId;
|
||||
query[Parameters.ClientSecret]=clientSecret;
|
||||
query[Parameters.Scope]=scope;
|
||||
query[Parameters.GrantType]=GrantTypes.Password;
|
||||
var result = await oauthor.RequestAccessTokenAsync(query);
|
||||
Console.WriteLine(">> Got an output");
|
||||
|
Reference in New Issue
Block a user