Skip to content

Commit eaea73e

Browse files
Remove unneeded client secret, this becomes optional if you uncheck the Confidential Application box
1 parent ba90f15 commit eaea73e

7 files changed

Lines changed: 21 additions & 22 deletions

File tree

BlazorWasmOsmOauth.AppHost/BlazorWasmOsmOauth.AppHost.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
<PropertyGroup>
66
<OutputType>Exe</OutputType>
7-
<!--RuntimeIdentifier>linux-x64</RuntimeIdentifier-->
87
<TargetFramework>net9.0</TargetFramework>
98
<Nullable>enable</Nullable>
109
<ImplicitUsings>enable</ImplicitUsings>
1110
<LangVersion>latest</LangVersion>
1211
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1312
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
1413
<IsAspireHost>true</IsAspireHost>
15-
<UserSecretsId>921895ce-56b3-40c7-849d-73de8158112b</UserSecretsId>
1614
</PropertyGroup>
1715

1816
<ItemGroup>

BlazorWasmOsmOauth/Models/AppConfig.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ public sealed class AppConfig
1717
/// </summary>
1818
public string ClientId { get; set; } = string.Empty;
1919

20-
/// <summary>
21-
/// Client Secret from OSM to use, get from: https://www.openstreetmap.org/oauth2/applications
22-
/// </summary>
23-
public string ClientSecret { get; set; } = string.Empty;
24-
2520
/// <summary>
2621
/// Base URL for the OSM OAuth API
2722
/// </summary>

BlazorWasmOsmOauth/Osm/OsmApiClient.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ public class OsmApiClient(IHttpClientFactory httpClientFactory)
2929
/// Get the user token from the OSM API, using the code from the OAuth2 flow. Or null if the request fails.
3030
/// </summary>
3131
/// <returns></returns>
32-
public async Task<TokenResponse?> GetTokenAsync(string code, string redirectUri, string clientId, string clientSecret)
32+
public async Task<TokenResponse?> GetTokenAsync(string code, string redirectUri, string clientId)
3333
{
34-
string queryStr = $"grant_type=authorization_code&code={HttpUtility.UrlEncode(code)}&redirect_uri={HttpUtility.UrlEncode(redirectUri)}&client_id={HttpUtility.UrlEncode(clientId)}&client_secret={HttpUtility.UrlEncode(clientSecret)}";
34+
string queryStr = "grant_type=authorization_code"
35+
+ $"&code={HttpUtility.UrlEncode(code)}"
36+
+ $"&redirect_uri={HttpUtility.UrlEncode(redirectUri)}"
37+
+ $"&client_id={HttpUtility.UrlEncode(clientId)}";
38+
3539
HttpResponseMessage response = await _authClient.PostAsync($"/oauth2/token?{queryStr}", new StringContent(string.Empty, Encoding.UTF8, "application/x-www-form-urlencoded"));
3640

3741
if (!response.IsSuccessStatusCode)

BlazorWasmOsmOauth/Pages/AuthCompletePage.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private async Task GetToken()
6363
return;
6464
}
6565

66-
TokenResponse? tokenResp = await osmClient.GetTokenAsync(Code, config.RedirectUri, config.ClientId, config.ClientSecret);
66+
TokenResponse? tokenResp = await osmClient.GetTokenAsync(Code, config.RedirectUri, config.ClientId);
6767

6868
if (tokenResp != null)
6969
{
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"OsmApiBaseUrl": "https://api06.dev.openstreetmap.org",
3-
"ClientId": "aXnhGfs4iwP_fCxbYGAc6kj6xcin6K7Iec1lriuAuqs",
4-
"ClientSecret": "Zmv1ogqPFy9omXtMlWfTl4ROZ8pgq7BjRTUXoWguJio",
5-
"OsmAuthBaseUrl": "https://master.apis.dev.openstreetmap.org"
6-
}
2+
"OsmApiBaseUrl": "https://api06.dev.openstreetmap.org",
3+
"ClientId": "0iCXHcIUNMOWXoZ2W9TxkqVfy4JemAX5g7ExU0JBQGg",
4+
"OsmAuthBaseUrl": "https://master.apis.dev.openstreetmap.org"
5+
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"OsmApiBaseUrl": "https://api06.dev.openstreetmap.org",
3-
"ClientId": "bioCyRFKB85wB70S0SPF09XIYXDxT_3mZ1RRrBWI-D4",
4-
"ClientSecret": "afcGoB5frxi4_yMUUlGH_8jxeCLUHGqWkDJWLkxoTJM",
5-
"OsmAuthBaseUrl": "https://master.apis.dev.openstreetmap.org"
6-
}
2+
"OsmApiBaseUrl": "https://api06.dev.openstreetmap.org",
3+
"ClientId": "8LxQ2LsL2LrgOdEwULmU-toNH6jQg9Nb5C8rxfeM8Ik",
4+
"OsmAuthBaseUrl": "https://master.apis.dev.openstreetmap.org"
5+
}

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
Example setup for Oauth with Blazor Webassembly.
44

5-
On the OSM side you'll want to configure the 'Redirect URI' to:
5+
When creating the Application in OSM make sure to uncheck the 'Confidential application?" box.
6+
7+
Also configure the 'Redirect URI' to:
68
- `http(s)://<domain or 127.0.0.1>/oauth2-redirect`
79

8-
The OSM Client ID and Client Secret are set via one of the following:
10+
Since this is an entirely client-side app there can be no client secret, so when OSM tells it to you just ignore that and copy the client ID.
11+
12+
The OSM Client ID is set via one of the following:
913
- `BlazorWasmOsmOauth/wwwroot/appsettings.Development.json`
1014
- `BlazorWasmOsmOauth/wwwroot/appsettings.Production.json`
1115

0 commit comments

Comments
 (0)