Restauration paramètres d'usine

This commit is contained in:
2016-06-12 02:31:59 +02:00
parent 6654e599c9
commit 8ce7767672
6 changed files with 39 additions and 61 deletions

View File

@ -136,9 +136,7 @@ namespace Yavsc.Controllers
}
string[] scopes = { };
string redirect_uri = null;
string client_id = null;
string state = null;
string redirect_uri=null;
IDictionary<string,StringValues> queryStringComponents = null;
@ -150,20 +148,11 @@ namespace Yavsc.Controllers
scopes = queryStringComponents["scope"];
if (queryStringComponents.ContainsKey("redirect_uri"))
redirect_uri = queryStringComponents["redirect_uri"];
if (queryStringComponents.ContainsKey("client_id"))
client_id = queryStringComponents["client_id"];
if (queryStringComponents.ContainsKey("state"))
state = queryStringComponents["state"];
}
var model = new AuthorisationView {
Scopes = Constants.SiteScopes.Where(s=> scopes.Contains(s.Id)).ToArray(),
RedirectUrl = redirect_uri,
Message = "Welcome.",
QueryStringComponents = queryStringComponents,
ClientId = client_id,
State = state,
ResponseType="code"
Message = "Welcome."
} ;
if (Request.Method == "POST")
@ -181,7 +170,13 @@ namespace Yavsc.Controllers
_logger.LogWarning("Logging user {principal} against {OAuthDefaults.AuthenticationType}");
await authentication.SignInAsync(OAuthDefaults.AuthenticationType, principal);
}
if (!string.IsNullOrEmpty(Request.Form["submit.Deny"]))
{
await authentication.SignOutAsync(appAuthSheme);
if (redirect_uri!=null)
return Redirect(redirect_uri+"?error=scope-denied");
return Redirect("/");
}
if (!string.IsNullOrEmpty(Request.Form["submit.Login"]))
{
await authentication.SignOutAsync(appAuthSheme);

View File

@ -5,13 +5,7 @@ namespace Yavsc.Models.Auth
{
public class AuthorisationView { 
public Scope[] Scopes { get; set; }
public string RedirectUrl { get; set; }
public string Message { get; set; }
public string ClientId {get; set; }
public string State {get; set; }
public string ResponseType { get; set; }
public IDictionary<string,StringValues> QueryStringComponents { get; set; }
}
}

View File

@ -1,32 +0,0 @@
@using Microsoft.AspNet.Http.Authentication
@using Microsoft.AspNet.WebUtilities
@using System.Security.Claims
@using Microsoft.Extensions.Primitives
@model Yavsc.Models.Auth.AuthorisationView
@{
ViewBag.Title = @SR["Authorize"];
}
<h1>Authorization Server</h1>
<h2>OAuth2 Authorize</h2>
<form method="POST" asp-action="Authorize" asp-controller="OAuth">
<p>Hello, @User.Identity.Name</p>
<p>@Model.Message</p>
<p>A third party application want to do the following on your behalf:</p>
<ul>
@foreach (var scope in Model.Scopes)
{
<li><em>@scope.Id</em>: @scope.Description</li>
}
</ul>
<p>
<input type="submit" class="btn btn-lg btn-success" name="submit.Grant" value="Grant" />
<input type="submit" class="btn btn-lg btn-danger" name="submit.Deny" value="Deny" />
<input type="submit" class="btn btn-lg btn-success" name="submit.Login" value="Sign in as different user" />
</p>
@if (Model.QueryStringComponents!=null) {
@foreach (var key in Model.QueryStringComponents.Keys) {
@Html.Hidden(key,Model.QueryStringComponents[key])
}
}
</form>

View File

@ -8,12 +8,7 @@
<h1>Authorization Server</h1>
<h2>OAuth2 Authorize</h2>
<form method="POST" asp-action="Authorize" asp-controller="OAuth"
asp-route-client_id="@Model.ClientId"
asp-route-redirect_url="@Model.RedirectUrl"
asp-route-state="@Model.State"
asp-route-response_type="@Model.ResponseType"
>
<form method="POST">
<p>Hello, @User.Identity.Name</p>
<p>@Model.Message</p>
<p>A third party application want to do the following on your behalf:</p>

View File

@ -0,0 +1,17 @@
@using Microsoft.AspNet.Http
@using System
@using System.Security.Claims
@{
var error = Context.Items["oauth.Error"];
var errorDescription = Context.Items["oauth.ErrorDescription"];
var errorUri = Context.Items["oauth.ErrorUri"];
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Authorization Denied</title>
</head>
<body>
<h1>Authorization denied</h1>
</body>
</html>

View File

@ -1,4 +1,5 @@

using System.Threading.Tasks;
using Microsoft.AspNet.Http.Authentication;
using Microsoft.AspNet.Mvc;
@ -6,12 +7,20 @@ namespace Mvc.Client.Controllers {
public class AuthenticationController : Controller {
[HttpGet("~/signin")]
public ActionResult SignIn() {
public ActionResult SignIn(string returnUrl="/") {
// Instruct the OIDC client middleware to redirect the user agent to the identity provider.
// Note: the authenticationType parameter must match the value configured in Startup.cs
var properties = new AuthenticationProperties { RedirectUri = "http://localhost:5002/signin-yavsc" };
// Note: the authenticationType parameter must match the value configured in Startup.cs.
// But, this redirect URI doesn't need to match the OAuth parameter, it's serialized in the query state,
// to be used once the identification ends.
var properties = new AuthenticationProperties { RedirectUri = returnUrl };
return new ChallengeResult("Yavsc", properties);
}
[HttpGet("~/signout")]
public async Task<IActionResult> SignOut(string returnUrl="/") {
await HttpContext.Authentication.SignOutAsync("Bearer");
return Redirect(returnUrl);
}
}
}