Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
add sid and device description to grants table (#4210)
Browse files Browse the repository at this point in the history
* add sid to grants table

* also add description to grants table
  • Loading branch information
brockallen committed Mar 30, 2020
1 parent 91f3211 commit bab4caf
Show file tree
Hide file tree
Showing 67 changed files with 501 additions and 95 deletions.
Expand Up @@ -85,9 +85,9 @@ public async Task<IActionResult> Login(LoginInputModel model, string button)
await _interaction.DenyAuthorizationAsync(context, AuthorizationError.AccessDenied);

// we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null
if (context.Client.IsPkceClient())
if (context.IsNativeClient())
{
// if the client is PKCE then we assume it's native, so this change in how to
// The client is native, so this change in how to
// return the response is for better UX for the end user.
return this.LoadingPage("Redirect", model.ReturnUrl);
}
Expand All @@ -111,9 +111,9 @@ public async Task<IActionResult> Login(LoginInputModel model, string button)

if (context != null)
{
if (context.Client.IsPkceClient())
if (context.IsNativeClient())
{
// if the client is PKCE then we assume it's native, so this change in how to
// The client is native, so this change in how to
// return the response is for better UX for the end user.
return this.LoadingPage("Redirect", model.ReturnUrl);
}
Expand Down
Expand Up @@ -150,9 +150,9 @@ public async Task<IActionResult> Callback()

if (context != null)
{
if (context.Client.IsPkceClient())
if (context.IsNativeClient())
{
// if the client is PKCE then we assume it's native, so this change in how to
// The client is native, so this change in how to
// return the response is for better UX for the end user.
return this.LoadingPage("Redirect", returnUrl);
}
Expand Down
Expand Up @@ -64,9 +64,10 @@ public async Task<IActionResult> Index(ConsentInputModel model)

if (result.IsRedirect)
{
if (result.Client.IsPkceClient())
var context = await _interaction.GetAuthorizationContextAsync(model.ReturnUrl);
if (context?.IsNativeClient() == true)
{
// if the client is PKCE then we assume it's native, so this change in how to
// The client is native, so this change in how to
// return the response is for better UX for the end user.
return this.LoadingPage("Redirect", result.RedirectUri);
}
Expand Down Expand Up @@ -123,7 +124,8 @@ private async Task<ProcessConsentResult> ProcessConsent(ConsentInputModel model)
grantedConsent = new ConsentResponse
{
RememberConsent = model.RememberConsent,
ScopesValuesConsented = scopes.ToArray()
ScopesValuesConsented = scopes.ToArray(),
Description = model.Description
};

// emit event
Expand Down Expand Up @@ -183,6 +185,7 @@ private async Task<ConsentViewModel> BuildViewModelAsync(string returnUrl, Conse
{
RememberConsent = model?.RememberConsent ?? true,
ScopesConsented = model?.ScopesConsented ?? Enumerable.Empty<string>(),
Description = model?.Description,

ReturnUrl = returnUrl,

Expand Down
Expand Up @@ -12,5 +12,6 @@ public class ConsentInputModel
public IEnumerable<string> ScopesConsented { get; set; }
public bool RememberConsent { get; set; }
public string ReturnUrl { get; set; }
public string Description { get; set; }
}
}
Expand Up @@ -106,7 +106,8 @@ private async Task<ProcessConsentResult> ProcessConsent(DeviceAuthorizationInput
grantedConsent = new ConsentResponse
{
RememberConsent = model.RememberConsent,
ScopesValuesConsented = scopes.ToArray()
ScopesValuesConsented = scopes.ToArray(),
Description = model.Description
};

// emit event
Expand Down Expand Up @@ -158,6 +159,7 @@ private DeviceAuthorizationViewModel CreateConsentViewModel(string userCode, Dev
var vm = new DeviceAuthorizationViewModel
{
UserCode = userCode,
Description = model?.Description,

RememberConsent = model?.RememberConsent ?? true,
ScopesConsented = model?.ScopesConsented ?? Enumerable.Empty<string>(),
Expand Down
25 changes: 5 additions & 20 deletions src/AspNetIdentity/host/Quickstart/Extensions.cs
@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;
using IdentityServer4.Models;
using IdentityServer4.Stores;
Expand All @@ -8,29 +9,13 @@ namespace IdentityServer4.Quickstart.UI
public static class Extensions
{
/// <summary>
/// Determines whether the client is configured to use PKCE.
/// Checks if the redirect URI is for a native client.
/// </summary>
/// <param name="store">The store.</param>
/// <param name="client_id">The client identifier.</param>
/// <returns></returns>
public static async Task<bool> IsPkceClientAsync(this IClientStore store, string client_id)
public static bool IsNativeClient(this AuthorizationRequest context)
{
if (!string.IsNullOrWhiteSpace(client_id))
{
var client = await store.FindEnabledClientByIdAsync(client_id);
return client.IsPkceClient();
}

return false;
}

/// <summary>
/// Checks is client is PKCE.
/// </summary>
/// <returns></returns>
public static bool IsPkceClient(this Client client)
{
return client?.RequirePkce == true;
return !context.RedirectUri.StartsWith("https", StringComparison.Ordinal)
&& !context.RedirectUri.StartsWith("http", StringComparison.Ordinal);
}

public static IActionResult LoadingPage(this Controller controller, string viewName, string redirectUri)
Expand Down
Expand Up @@ -61,7 +61,7 @@ public async Task<IActionResult> Revoke(string clientId)

private async Task<GrantsViewModel> BuildViewModelAsync()
{
var grants = await _interaction.GetAllUserConsentsAsync();
var grants = await _interaction.GetAllUserGrantsAsync();

var list = new List<GrantViewModel>();
foreach(var grant in grants)
Expand All @@ -77,6 +77,7 @@ private async Task<GrantsViewModel> BuildViewModelAsync()
ClientName = client.ClientName ?? client.ClientId,
ClientLogoUrl = client.LogoUri,
ClientUrl = client.ClientUri,
Description = grant.Description,
Created = grant.CreationTime,
Expires = grant.Expiration,
IdentityGrantNames = resources.IdentityResources.Select(x => x.DisplayName ?? x.Name).ToArray(),
Expand Down
Expand Up @@ -18,6 +18,7 @@ public class GrantViewModel
public string ClientName { get; set; }
public string ClientUrl { get; set; }
public string ClientLogoUrl { get; set; }
public string Description { get; set; }
public DateTime Created { get; set; }
public DateTime? Expires { get; set; }
public IEnumerable<string> IdentityGrantNames { get; set; }
Expand Down
10 changes: 10 additions & 0 deletions src/AspNetIdentity/host/Views/Consent/Index.cshtml
Expand Up @@ -55,6 +55,16 @@
</div>
}

<div class="panel panel-default">
<div class="panel-heading">
<span class="glyphicon glyphicon-tasks"></span>
Device Description
</div>
<div class="panel-body">
<input class="form-control" placeholder="Description or name of device" asp-for="Description" autofocus>
</div>
</div>

@if (Model.AllowRememberConsent)
{
<div class="consent-remember">
Expand Down
33 changes: 24 additions & 9 deletions src/AspNetIdentity/host/Views/Device/UserCodeCapture.cshtml
@@ -1,14 +1,29 @@
@model string

<div class="page-header">
<h1>
User Code
</h1>
<div>
<div class="page-header">
<h1>User Code</h1>
</div>
<p>
Please enter the code displayed on your device
</p>
<form asp-action="UserCodeCapture" method="post">
<input for="userCode" name="userCode" />
<button class="btn btn-primary">Submit</button>
</form>
</div>

<partial name="_ValidationSummary" />

<div class="row">
<div class="col-sm-6">
<form asp-action="UserCodeCapture">
<fieldset>
<div class="form-group">
<label for="userCode">User Code:</label>
<input class="form-control" for="userCode" name="userCode" autofocus />
</div>

<div class="form-group">
<button class="btn btn-primary" name="button">Submit</button>
</div>
</fieldset>
</form>
</div>
</div>
</div>
10 changes: 10 additions & 0 deletions src/AspNetIdentity/host/Views/Device/UserCodeConfirmation.cshtml
Expand Up @@ -66,6 +66,16 @@
</div>
}

<div class="panel panel-default">
<div class="panel-heading">
<span class="glyphicon glyphicon-tasks"></span>
Device Description
</div>
<div class="panel-body">
<input class="form-control" placeholder="Description or name of device" asp-for="Description" autofocus>
</div>
</div>

@if (Model.AllowRememberConsent)
{
<div class="consent-remember">
Expand Down
6 changes: 6 additions & 0 deletions src/AspNetIdentity/host/Views/Grants/Index.cshtml
Expand Up @@ -33,6 +33,12 @@
</div>
<div class="col-sm-8">
<div class="clientname">@grant.ClientName</div>
@if (grant.Description != null)
{
<div>
<span class="expires">Description:</span> @grant.Description
</div>
}
<div>
<span class="created">Created:</span> @grant.Created.ToString("yyyy-MM-dd")
</div>
Expand Down
Expand Up @@ -375,7 +375,7 @@ CREATE UNIQUE INDEX [IX_IdentityResources_Name] ON [IdentityResources] ([Name]);
GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20200323135102_Config', N'3.1.0');
VALUES (N'20200327191244_Config', N'3.1.0');

GO

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -13,7 +13,9 @@ CREATE TABLE [DeviceCodes] (
[UserCode] nvarchar(200) NOT NULL,
[DeviceCode] nvarchar(200) NOT NULL,
[SubjectId] nvarchar(200) NULL,
[SessionId] nvarchar(100) NULL,
[ClientId] nvarchar(200) NOT NULL,
[Description] nvarchar(200) NULL,
[CreationTime] datetime2 NOT NULL,
[Expiration] datetime2 NOT NULL,
[Data] nvarchar(max) NOT NULL,
Expand All @@ -26,7 +28,9 @@ CREATE TABLE [PersistedGrants] (
[Key] nvarchar(200) NOT NULL,
[Type] nvarchar(50) NOT NULL,
[SubjectId] nvarchar(200) NULL,
[SessionId] nvarchar(100) NULL,
[ClientId] nvarchar(200) NOT NULL,
[Description] nvarchar(200) NULL,
[CreationTime] datetime2 NOT NULL,
[Expiration] datetime2 NULL,
[Data] nvarchar(max) NOT NULL,
Expand All @@ -51,8 +55,12 @@ CREATE INDEX [IX_PersistedGrants_SubjectId_ClientId_Type] ON [PersistedGrants] (

GO

CREATE INDEX [IX_PersistedGrants_SubjectId_SessionId_Type] ON [PersistedGrants] ([SubjectId], [SessionId], [Type]);

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20200323135058_Grants', N'3.1.0');
VALUES (N'20200327191239_Grants', N'3.1.0');

GO

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -14,7 +14,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
UserCode = table.Column<string>(maxLength: 200, nullable: false),
DeviceCode = table.Column<string>(maxLength: 200, nullable: false),
SubjectId = table.Column<string>(maxLength: 200, nullable: true),
SessionId = table.Column<string>(maxLength: 100, nullable: true),
ClientId = table.Column<string>(maxLength: 200, nullable: false),
Description = table.Column<string>(maxLength: 200, nullable: true),
CreationTime = table.Column<DateTime>(nullable: false),
Expiration = table.Column<DateTime>(nullable: false),
Data = table.Column<string>(maxLength: 50000, nullable: false)
Expand All @@ -31,7 +33,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
Key = table.Column<string>(maxLength: 200, nullable: false),
Type = table.Column<string>(maxLength: 50, nullable: false),
SubjectId = table.Column<string>(maxLength: 200, nullable: true),
SessionId = table.Column<string>(maxLength: 100, nullable: true),
ClientId = table.Column<string>(maxLength: 200, nullable: false),
Description = table.Column<string>(maxLength: 200, nullable: true),
CreationTime = table.Column<DateTime>(nullable: false),
Expiration = table.Column<DateTime>(nullable: true),
Data = table.Column<string>(maxLength: 50000, nullable: false)
Expand Down Expand Up @@ -61,6 +65,11 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "IX_PersistedGrants_SubjectId_ClientId_Type",
table: "PersistedGrants",
columns: new[] { "SubjectId", "ClientId", "Type" });

migrationBuilder.CreateIndex(
name: "IX_PersistedGrants_SubjectId_SessionId_Type",
table: "PersistedGrants",
columns: new[] { "SubjectId", "SessionId", "Type" });
}

protected override void Down(MigrationBuilder migrationBuilder)
Expand Down

0 comments on commit bab4caf

Please sign in to comment.