-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
261 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Newtonsoft.Json.Schema; | ||
|
||
namespace KratosSelfService.Services; | ||
|
||
public class IdentitySchemaService | ||
{ | ||
private readonly HttpClient _httpClient = new(); | ||
private readonly Dictionary<string, JSchema> _schemaCache = new(); | ||
|
||
public async Task<JSchema> FetchSchema(string schemaId, string schemaUri) | ||
{ | ||
// check if schema object is cached | ||
if (_schemaCache.TryGetValue(schemaId, out var schema)) | ||
return schema; | ||
var response = await _httpClient.GetStringAsync(schemaUri); | ||
// request and cache new schema object | ||
_schemaCache[schemaId] = JSchema.Parse(response); | ||
return _schemaCache[schemaId]; | ||
} | ||
|
||
public static Dictionary<List<string>, JSchema> GetTraits(JSchema schema) | ||
{ | ||
var traits = schema.Properties["traits"].Properties; | ||
return FlattenTraits(traits, []); | ||
} | ||
|
||
private static Dictionary<List<string>, JSchema> FlattenTraits(IDictionary<string, JSchema> traits, | ||
IReadOnlyCollection<string> pathSections) | ||
{ | ||
var map = new Dictionary<List<string>, JSchema>(); | ||
foreach (var (traitKey, trait) in traits) | ||
{ | ||
var newPathSections = new List<string>(pathSections) { traitKey }; | ||
switch (trait.Type) | ||
{ | ||
case JSchemaType.Object: | ||
foreach (var entry in FlattenTraits(trait.Properties, newPathSections)) | ||
map[entry.Key] = entry.Value; | ||
break; | ||
case JSchemaType.Array: | ||
// TODO support arrays | ||
break; | ||
default: // string, etc. | ||
map[newPathSections] = trait; | ||
break; | ||
} | ||
} | ||
|
||
return map; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
KratosSelfService/Views/Home/Home.cshtml → KratosSelfService/Views/Home/Links.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
@using OryAdmin.Extensions | ||
@using Newtonsoft.Json.Linq | ||
@model ProfileModel | ||
@{ | ||
ViewData["Title"] = "View Profile"; | ||
Layout = "_Layout"; | ||
var traits = (JObject)Model.session.Identity.Traits; | ||
} | ||
|
||
<section class="hero has-background-white-ter is-fullheight"> | ||
<div class="hero-body"> | ||
<div class="container"> | ||
<div class="columns is-centered"> | ||
<div class="column is-10-tablet is-8-desktop is-6-widescreen"> | ||
<div class="box"> | ||
<h1 class="title"> | ||
@CustomTranslator.Get("Hello") @traits.GetTraitValueFromPath(["name", "first"]) | ||
</h1> | ||
<div class="columns is-one-third"> | ||
<div class="column"> | ||
<figure class="image is-128x128"> | ||
<img alt="Profile picture" class="is-rounded" | ||
src="img/Missing_avatar.svg"> | ||
</figure> | ||
</div> | ||
<div class="column is-two-thirds"> | ||
<table class="table is-fullwidth"> | ||
<tbody> | ||
@foreach (var (schemaPathSections, schema) in Model.traitSchemas) | ||
{ | ||
<tr> | ||
<td>@schema.Title</td> | ||
<td>@traits.GetTraitValueFromPath(schemaPathSections)</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
<hr/> | ||
<div class="buttons is-right mt-3"> | ||
<a class="button is-info" href="settings">@OryTranslator.Get("settings.title")</a> | ||
<a class="button is-info" href="sessions">@CustomTranslator.Get("sessions.title")</a> | ||
<a class="button is-warning" href="logout">@CustomTranslator.Get("Logout")</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Kratos/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Kratos/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Wellknown/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=KratosSelfService_002FResources_002FCustomTranslator/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary> |