An Oauth client handler, from abstract

This commit is contained in:
Paul Schneider 2018-07-25 02:12:13 +02:00
commit fca6b46c92
18 changed files with 710 additions and 649 deletions

View file

@ -3,7 +3,10 @@
// paul 21/06/2018 10:11 20182018 6 21
// */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Builder.Internal;
using Microsoft.Data.Entity;
@ -14,15 +17,19 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.OptionsModel;
using Microsoft.Extensions.PlatformAbstractions;
using Newtonsoft.Json;
using Xunit;
using Xunit.Abstractions;
using Yavsc;
using Yavsc.Authentication;
using Yavsc.Lib;
using Yavsc.Models;
using static OAuth.AspNet.AuthServer.Constants;
namespace test
{
[Collection("Yavsc Work In Progress")]
[Trait("noregres", "no")]
public class YavscWorkInProgress : BaseTestContext, IClassFixture<ServerSideFixture>
{
@ -34,17 +41,59 @@ namespace test
_serverFixture = serverFixture;
}
[Fact]
public void GitClone()
[Theory]
[InlineData("d9be5e97-c19d-42e4-b444-0e65863b19e1","blouh","profile",
"http://localhost:5000/authorize",
"http://localhost:5000/oauth/success",
"http://localhost:5000/token",
"joe",
"badpass"
)]
public async Task TestUserMayLogin
(
string clientId,
string clientSecret,
string scope,
string authorizeUrl,
string redirectUrl,
string accessTokenUrl,
string login,
string pass
)
{
var dbc = _serverFixture._app.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
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");
Console.WriteLine(Parameters.AccessToken+": "+result[Parameters.AccessToken]);
Console.WriteLine(Parameters.TokenType+": "+result[Parameters.TokenType]);
Console.WriteLine(Parameters.ExpiresIn+": "+result[Parameters.ExpiresIn]);
Console.WriteLine(Parameters.RefreshToken+": "+result[Parameters.RefreshToken]);
var firstProject = dbc.Projects.Include(p=>p.Repository).FirstOrDefault();
Assert.NotNull (firstProject);
var clone = new GitClone(_serverFixture._siteSetup.GitRepository);
clone.Launch(firstProject);
}
catch (Exception ex)
{
var webex = ex as WebException;
if (webex!=null && webex.Status == (WebExceptionStatus)400)
{
if (login == "joe") {
Console.WriteLine("Bad pass joe!");
return;
}
}
throw;
}
}
}
}