Skip to content

Commit dff2111

Browse files
committed
Update documentation for configuring AuthSCH
1 parent 8e93356 commit dff2111

4 files changed

Lines changed: 75 additions & 23 deletions

File tree

README.md

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,34 @@ Instructions on how to quickly set up a development environment.
1818
- [bun](https://bun.sh/docs/installation)
1919
- make sure you can run `bun`
2020

21-
### AuthSCH credentials
22-
23-
https://auth.sch.bme.hu > *Bejelentkezés* > *Fejlesztői konzol* > *Új hozzáadása*, set *Átirányítási cím* to
24-
`http://localhost:5264/signin-oidc`,
25-
then use the created credentials in the following commands:
26-
2721
### Running from the terminal
2822

2923
```shell
3024
git clone https://github.com/kir-dev/StartSCH
3125
cd StartSCH/StartSch
32-
dotnet user-secrets set AuthSch:ClientId REPLACE_THIS_WITH_YOUR_AUTHSCH_CLIENTID
33-
dotnet user-secrets set AuthSch:ClientSecret REPLACE_THIS_WITH_YOUR_AUTHSCH_CLIENTSECRET
3426
dotnet run
3527
```
3628

37-
### Debugging
29+
### IDE
3830

39-
I recommend using JetBrains' .NET IDE, Rider for working on StartSCH. Below you can find instructions on how run StartSCH in debug mode using it:
31+
I recommend using JetBrains' .NET IDE, Rider for working on StartSCH.
32+
Below you can find instructions on how to run StartSCH in debug mode using it:
4033

4134
1. [Install Rider](https://www.jetbrains.com/rider/download/)
42-
2. Open `StartSCH.slnx`
43-
3. Ensure AuthSCH credentials are correctly set up: *Explorer* > *StartSch* > right-click > *Tools* > *.NET User Secrets*
35+
2. Open `StartSCH.slnx` with Rider
36+
3. [Set the Run Configuration](https://www.jetbrains.com/help/rider/Run_Debug_Configuration.html#launch-run-configuration)
37+
to *StartSch: http*
4438
4. Click *Debug 'StartSch'* (the green bug icon in the top right) or press `F5`
4539

4640
[//]: # (TODO: add details about WASM debugging. Perhaps create a separate doc for it?)
4741

4842
### Running with hot reloading
4943

5044
Hot reloading allows updating the code of the app while it is running without restarting it.
51-
Rider's built-in hot reloading is not that great, so I highly recommend just running StartSCH from the terminal if you don't need a debugger:
45+
It is especially useful when working on UI code.
46+
47+
Rider's built-in hot reloading is useless, so I highly recommend just running StartSCH
48+
from the terminal if you don't need a debugger.
5249

5350
#### Terminal 1
5451
```sh
@@ -58,6 +55,9 @@ cd StartSCH/StartSch
5855
dotnet watch
5956
```
6057

58+
.NET Hot Reload only works for smaller changes, and even at that it still sometimes fails,
59+
so you will have to restart the app quite often.
60+
6161
#### Terminal 2
6262
```shell
6363
cd StartSCH/StartSch
@@ -69,9 +69,11 @@ bun watch
6969

7070
## Development
7171

72+
Everything you might need to know to work on StartSCH.
73+
7274
### Overview
7375

74-
If you don't like reading, check out these files and directories for a quick overview of the project:
76+
If you don't like reading, skim these files and directories for a quick overview of the project:
7577

7678
- [`StartSch/`](StartSch)
7779
- [`Program.cs`](StartSch/Program.cs): the entrypoint of the server
@@ -146,13 +148,34 @@ Examples:
146148

147149
`SchPincerModule` is enabled by default in `appsettings.Development.json`.
148150

149-
### Setting up push notifications
151+
#### Configuring AuthSCH
152+
153+
### AuthSCH credentials
154+
155+
https://auth.sch.bme.hu > *Bejelentkezés* > *Fejlesztői konzol* > *Új hozzáadása*, set *Átirányítási cím* to
156+
`http://localhost:5264/signin-oidc`,
157+
then set `AuthSch:ClientId` and `AuthSch:ClientSecret` configuration values, for example using user secrets:
158+
```shell
159+
cd StartSCH/StartSch
160+
dotnet user-secrets set AuthSch:ClientId REPLACE_THIS_WITH_YOUR_AUTHSCH_CLIENTID
161+
dotnet user-secrets set AuthSch:ClientSecret REPLACE_THIS_WITH_YOUR_AUTHSCH_CLIENTSECRET
162+
dotnet run
163+
```
164+
or environment variables:
165+
```shell
166+
AuthSch__ClientId=REPLACE_THIS_WITH_YOUR_AUTHSCH_CLIENTID
167+
AuthSch__ClientSecret=REPLACE_THIS_WITH_YOUR_AUTHSCH_CLIENTSECRET
168+
```
169+
170+
Once the credentials are set, StartSCH will allow logging in with AuthSCH.
171+
172+
#### Configuring Web Push notifications
150173

151174
- [MDN: Web Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API)
152175
- [web.dev: Push notifications overview](https://web.dev/articles/push-notifications-overview)
153176

154177
To send push notifications, most push services,
155-
[for example, Apple](https://developer.apple.com/documentation/usernotifications/sending-web-push-notifications-in-web-apps-and-browsers#Prepare-your-server-to-send-push-notifications),
178+
[for example, Apple's](https://developer.apple.com/documentation/usernotifications/sending-web-push-notifications-in-web-apps-and-browsers#Prepare-your-server-to-send-push-notifications),
156179
require a [VAPID](https://rfc-editor.org/rfc/rfc8292) key pair.
157180

158181
If you want to try out push notifications, you can use a [VAPID key generator](https://steveseguin.github.io/vapid/)
@@ -163,7 +186,8 @@ cd StartSCH/StartSch
163186

164187
dotnet user-secrets set Push:PublicKey "..."
165188
dotnet user-secrets set Push:PrivateKey "..."
166-
# Push service providers use this if there are issues with a sender, probably not important when developing
189+
# Push service providers use this if there are issues with a sender,
190+
# probably not important when developing but do ensure it is set to something.
167191
dotnet user-secrets set Push:Subject "mailto:example@example.com"
168192
```
169193

StartSch/Components/Pages/AuthenticationDevPage.razor

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@
1414
@if (!HostEnvironment.IsDevelopment())
1515
return;
1616

17+
@if (FromAuthSchLogin is { })
18+
{
19+
<section style="margin: 16px 0; padding: 16px; border-radius: 16px; background-color: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); line-height: 1.6">
20+
<md-icon>
21+
lightbulb_2
22+
</md-icon>
23+
<h2>
24+
Enabling AuthSCH sign-in
25+
</h2>
26+
<p>
27+
Get a client ID and secret from auth.sch.bme.hu and add them to your StartSCH configuration:
28+
</p>
29+
<a href="https://github.com/kir-dev/StartSCH#configuring-authsch" style="font-weight: bold">
30+
github.com/kir-dev/StartSCH#configuring-authsch
31+
</a>
32+
</section>
33+
}
34+
1735
<Title>Fejlesztői bejelentkezés</Title>
1836

1937
<AuthorizeView Context="_">
@@ -63,6 +81,9 @@
6381
[SupplyParameterFromQuery(Name = "ReturnUrl")]
6482
private string? ReturnUrl { get; set; }
6583

84+
[SupplyParameterFromQuery(Name = "from-authsch-login")]
85+
private string? FromAuthSchLogin { get; set; }
86+
6687
protected override void OnInitialized() => Model ??= new();
6788

6889
private async Task SignIn()

StartSch/Controllers/AuthenticationController.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ namespace StartSch.Controllers;
55

66
// Based on https://learn.microsoft.com/en-us/aspnet/core/blazor/security/blazor-web-app-with-oidc?view=aspnetcore-8.0&pivots=without-bff-pattern
77
[ApiController]
8-
public class AuthenticationController : ControllerBase
8+
public class AuthenticationController(
9+
IHostEnvironment hostEnvironment,
10+
IAuthenticationSchemeProvider authenticationSchemeProvider
11+
) : ControllerBase
912
{
1013
[HttpGet("/authentication/login")]
11-
public ChallengeResult Login([FromQuery] string? returnUrl)
14+
public async Task<IActionResult> Login([FromQuery] string? returnUrl)
1215
{
13-
return Challenge(new AuthenticationProperties()
16+
if (hostEnvironment.IsDevelopment()
17+
&& await authenticationSchemeProvider.GetSchemeAsync(Constants.AuthSchAuthenticationScheme) is null)
18+
return Redirect("/authentication/dev?from-authsch-login");
19+
20+
return Challenge(new AuthenticationProperties
1421
{
1522
RedirectUri = GetReturnUrl(returnUrl, Request.PathBase),
16-
IsPersistent = true
23+
IsPersistent = true,
1724
});
1825
}
1926

@@ -26,7 +33,6 @@ public SignOutResult Logout([FromForm] string? returnUrl)
2633
{
2734
RedirectUri = GetReturnUrl(returnUrl, Request.PathBase)
2835
},
29-
3036
[
3137
Constants.CookieAuthenticationScheme,
3238

@@ -43,7 +49,7 @@ public SignOutResult Logout([FromForm] string? returnUrl)
4349
);
4450
}
4551

46-
private static string? GetReturnUrl(string? returnUrl, string pathBase)
52+
private static string GetReturnUrl(string? returnUrl, string pathBase)
4753
{
4854
// Prevent open redirects
4955
if (string.IsNullOrEmpty(returnUrl))

StartSch/Services/FontCache.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public class FontCache
6969
"history",
7070
"home",
7171
"lightbulb",
72+
"lightbulb_2",
7273
"link",
7374
"link_2",
7475
"location_on",

0 commit comments

Comments
 (0)