<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="/disco-blog/feed.xml" rel="self" type="application/atom+xml" /><link href="/disco-blog/" rel="alternate" type="text/html" /><updated>2026-09-29T02:53:27+00:00</updated><id>/disco-blog/feed.xml</id><title type="html">Disco Blog</title><subtitle>Weekly blog for Disco Tray Studios work.</subtitle><entry><title type="html">Authorization working now</title><link href="/disco-blog/2026/09/28/authorization.html" rel="alternate" type="text/html" title="Authorization working now" /><published>2026-09-28T00:00:00+00:00</published><updated>2026-09-28T00:00:00+00:00</updated><id>/disco-blog/2026/09/28/authorization</id><content type="html" xml:base="/disco-blog/2026/09/28/authorization.html"><![CDATA[<h2 id="obligatory-gitgh-troubles">Obligatory git/GH troubles</h2>
<p>I’ve been making good use of git branches, though I have to say my poor foresight in not knowing authorization was going to be a big task reared its head where I now have a <code class="language-plaintext highlighter-rouge">auth</code> (authentication) and an <code class="language-plaintext highlighter-rouge">authorization</code> (authorization) branch on my fork. Me and Drew also found out that apparently commits made after a PR is made aren’t automatically added to the PR.</p>

<h2 id="authorization">Authorization</h2>
<p>Dr. Goadrich made some roles in the Azure backend, though he didn’t do them right first because the example in the textbox misled him, making a role for an admin be <code class="language-plaintext highlighter-rouge">name: Admin</code> and <code class="language-plaintext highlighter-rouge">value: Everything.Update</code>. Every tutorial I saw was written like <code class="language-plaintext highlighter-rouge">[Authorization(Roles = "Admin"]</code>, so I was confused when I was debugging why that didn’t work and saw that my role was apparently <code class="language-plaintext highlighter-rouge">Everything.Update</code>. We met and he changed all the role values to be the same as the names. Thanks Microsoft?</p>

<p>Important discovery: if the user is logged in, in page models there’ll now be a <code class="language-plaintext highlighter-rouge">User</code> object which is an instance of <code class="language-plaintext highlighter-rouge">ClaimsPrincipal</code>. From there there’s a <code class="language-plaintext highlighter-rouge">Claims</code> property, which spits out a bunch of garbage as a linq key-value list of <code class="language-plaintext highlighter-rouge">Type, Value</code>. I say garbage because most of the entries are three letter something-acronyms and the values range from gibberish in hexadecimal to gibberish in hexadecimal with differing alpha case with regular slashes and pluses. Anyway, the entries that matter are <code class="language-plaintext highlighter-rouge">preferred_username</code>, <code class="language-plaintext highlighter-rouge">name</code>, and <code class="language-plaintext highlighter-rouge">roles</code>, which are the email, <code class="language-plaintext highlighter-rouge">Last, First</code> name of the user, and the user’s roles (how does it look with multiple roles?). I got that information because I made a <code class="language-plaintext highlighter-rouge">/Debug</code> page that prints the user’s claims, which I hope to add more info to as I need it. You’re a peasant if you debug with print statements! (t. peasant)</p>

<p>Because of the confusion before, I decided it would be better to use policies for authorization so I didn’t have to hardcode the roles in each page. Policies turned out to be more annoying, and I eventually switched to just using <code class="language-plaintext highlighter-rouge">ClaimsPrincipal.IsInRole()</code>. By the way, <code class="language-plaintext highlighter-rouge">[Authorize(Roles = "Admin,Committee,Evaluator")]</code> works as a boolean OR but <code class="language-plaintext highlighter-rouge">IsInRole("Admin,Committee,Evaluator")</code> doesn’t. Thanks Microsoft!</p>

<p>Then it was just a matter of getting that <code class="language-plaintext highlighter-rouge">IsInRole</code> method to actually work. The tutorial was surprisingly helpful, but still didn’t really explain what was going on. Thus sits these lines now in <code class="language-plaintext highlighter-rouge">Program.cs</code>:</p>
<div class="language-c# highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// Roles are sent as a "roles" claim.</span>
<span class="n">options</span><span class="p">.</span><span class="n">TokenValidationParameters</span><span class="p">.</span><span class="n">NameClaimType</span> <span class="p">=</span> <span class="n">JwtRegisteredClaimNames</span><span class="p">.</span><span class="n">Name</span><span class="p">;</span>
<span class="n">options</span><span class="p">.</span><span class="n">TokenValidationParameters</span><span class="p">.</span><span class="n">RoleClaimType</span> <span class="p">=</span> <span class="s">"roles"</span><span class="p">;</span>

<span class="c1">// I don't know what these do.</span>
<span class="n">options</span><span class="p">.</span><span class="n">MapInboundClaims</span> <span class="p">=</span> <span class="k">false</span><span class="p">;</span>
<span class="n">options</span><span class="p">.</span><span class="n">ResponseType</span> <span class="p">=</span> <span class="n">OpenIdConnectResponseType</span><span class="p">.</span><span class="n">Code</span><span class="p">;</span>
<span class="n">options</span><span class="p">.</span><span class="n">SaveTokens</span> <span class="p">=</span> <span class="k">true</span><span class="p">;</span>
<span class="n">options</span><span class="p">.</span><span class="n">GetClaimsFromUserInfoEndpoint</span> <span class="p">=</span> <span class="k">true</span><span class="p">;</span>
</code></pre></div></div>
<p>Do you know what these do?</p>

<hr />

<p>The page model of <code class="language-plaintext highlighter-rouge">/Evaluate</code> doesn’t hardcode the <code class="language-plaintext highlighter-rouge">Evaluator</code> property anymore. It selects for an evaluator whose email matches the logged in user’s one, but if it doesn’t find one it creates an evaluator instead. This really should be done whenever someone logs in (for both evaluators and students), but I made an issue for it. It’s kinda weird syncing data from the Microsoft server and our local db: having all the pages work with cookie-based authorization yet we still keep track of a local <code class="language-plaintext highlighter-rouge">Rank</code> property on each evaluator, and it’s never actually used anywhere, but I think removing it is probably a mistake.</p>

<h2 id="end">End</h2>
<p>Ultimately it’s in a state now that you can log in/log out, are only shown nav links to pages that you’re allowed to access, in actuality can only access pages you’re allowed to access, and the evaluator in the page model of <code class="language-plaintext highlighter-rouge">/Evaluate</code> isn’t hardcoded anymore. I realized that <code class="language-plaintext highlighter-rouge">/Review</code> doesn’t actually need per-evaluator authorization so I removed the <code class="language-plaintext highlighter-rouge">Evaluator</code> property from its page model.</p>

<p>The next big step is now to work on a student front end to submit packets to, but that’ll be a bit annoying until we can get student accounts for testing. I sent an email to the help desk requesting test accounts so we don’t have to rely on emulating 4 different roles with 3 accounts, 2 of which are actively working on it and need to be able to access every page lol.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Obligatory git/GH troubles I’ve been making good use of git branches, though I have to say my poor foresight in not knowing authorization was going to be a big task reared its head where I now have a auth (authentication) and an authorization (authorization) branch on my fork. Me and Drew also found out that apparently commits made after a PR is made aren’t automatically added to the PR.]]></summary></entry><entry><title type="html">Authentication working now</title><link href="/disco-blog/2026/09/22/authentication.html" rel="alternate" type="text/html" title="Authentication working now" /><published>2026-09-22T00:00:00+00:00</published><updated>2026-09-22T00:00:00+00:00</updated><id>/disco-blog/2026/09/22/authentication</id><content type="html" xml:base="/disco-blog/2026/09/22/authentication.html"><![CDATA[<p>First thing that I did was follow the tutorial at https://learn.microsoft.com/en-us/aspnet/core/security/authentication/configure-oidc-web-authentication?view=aspnetcore-10.0, which is ultimately enough to set it up but not enough to troubleshoot the apparently herculean task of setting up a correct dev environment. I ran into a dumb error and waited till our intermediary meeting since I thought I’d need Dr. Goadrich to debug it on his admin dashboard like last semester.</p>

<p>On Monday we met and Dr. Goadrich revealed what was the last hurdle to getting authentication to work: use https lol. This had been something that I was annoyed at before, but it was ultimately really simple: do the things in the Microsoft tutorial from Google, but I thought it wasn’t working since I was getting an error trying to access <code class="language-plaintext highlighter-rouge">https://localhost:5001</code>. Turns out that <code class="language-plaintext highlighter-rouge">dotnet run</code> was just serving http even though my browser wanted https; what worked was deleting the http method in <code class="language-plaintext highlighter-rouge">appsettings.json</code>. It took me a long time to realize since I thought if it wasn’t serving https at all the browser would give a 404 instead, but I guess the protocol in the url is only used for the browser’s interpretation of whatever it receives? So authentication works now, and I’m working on fleshing out the implementation in my branch, and I’ve already committed the minimal changes that allow you to log in and log out.</p>

<p>During that meeting I also inquired about a favicon, and Dr. Goadrich made one: the Hendrix shield + bar but with a cross cut out in the middle. When I got home and checked it, the cross was off-center (how could you) so I remade it and made a PR.</p>

<p>Throughout that now on Monday night I had some hiccups with Git. I had been committing everything to <code class="language-plaintext highlighter-rouge">main</code> but now I had two changes and remembered Dr. Goadrich saying to make a new branch since PRs apply to entire branches. So I had to reorganize the already existing commits into <code class="language-plaintext highlighter-rouge">auth</code> and <code class="language-plaintext highlighter-rouge">favicon</code> and also sync <code class="language-plaintext highlighter-rouge">main</code> to upstream. Learned (and will hopefully remember) some new commands:</p>
<ul>
  <li><code class="language-plaintext highlighter-rouge">git reset [file]</code> unstage “file”</li>
  <li><code class="language-plaintext highlighter-rouge">git branch</code> view branches</li>
  <li><code class="language-plaintext highlighter-rouge">git checkout [branch]</code> switch to branch “branch”</li>
  <li><code class="language-plaintext highlighter-rouge">git checkout -b [branch]</code> create branch “branch”</li>
</ul>

<p>Overall, really happy authentication is working now. Once I finish this all these other things up we can start working on the main essential features that were blocked, like only allowing users of certain privileges into certain parts of the website, or only showing assigned evaluation requests to the one it’s assigned to. At that point we’ll finally have an alpha version. 邁進せいっ!</p>]]></content><author><name></name></author><summary type="html"><![CDATA[First thing that I did was follow the tutorial at https://learn.microsoft.com/en-us/aspnet/core/security/authentication/configure-oidc-web-authentication?view=aspnetcore-10.0, which is ultimately enough to set it up but not enough to troubleshoot the apparently herculean task of setting up a correct dev environment. I ran into a dumb error and waited till our intermediary meeting since I thought I’d need Dr. Goadrich to debug it on his admin dashboard like last semester.]]></summary></entry></feed>