Skip to content

Commit c5259e8

Browse files
committed
Fix: Login
1 parent 672bdba commit c5259e8

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/OneWare.CloudIntegration/Services/OneWareCloudLoginService.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -482,14 +482,13 @@ public async Task<bool> LoginAsync(CancellationToken cancellationToken = default
482482
_state = GenerateState();
483483

484484
var authQueryParams = HttpUtility.ParseQueryString(string.Empty);
485-
authQueryParams["client_id"] = "OneWareStudio";
485+
authQueryParams["client_id"] = "Empty";
486486
authQueryParams["redirect_uri"] = redirectUri;
487487
authQueryParams["response_type"] = "code";
488488
authQueryParams["scope"] = "openid profile email";
489489
authQueryParams["code_challenge"] = codeChallenge;
490490
authQueryParams["code_challenge_method"] = "S256";
491491
authQueryParams["state"] = _state;
492-
authQueryParams["prompt"] = "consent";
493492
string authUrl = $"{authProviderBaseUrl}/protocol/openid-connect/auth?{authQueryParams}";
494493

495494
if (startNewListener)
@@ -514,7 +513,7 @@ public async Task<bool> LoginAsync(CancellationToken cancellationToken = default
514513
var code1 = query1["code"];
515514
var state1 = query1["state"];
516515
var error1 = query1["error"];
517-
516+
518517
if (!string.IsNullOrWhiteSpace(error1))
519518
{
520519
_logger.Error($"Authentication error (step 1): {error1}");
@@ -530,8 +529,9 @@ public async Task<bool> LoginAsync(CancellationToken cancellationToken = default
530529
step1Response.Close();
531530
return false;
532531
}
533-
534-
await ExchangeCodeForTokensAsync(code1, authProviderBaseUrl, redirectUri, persistTokens: false);
532+
533+
await ExchangeCodeForTokensAsync(code1, authProviderBaseUrl, redirectUri,
534+
persistTokens: false, clientIdOverride: "Empty");
535535

536536
_offlineCodeVerifier = GenerateCodeVerifier();
537537
string offlineCodeChallenge = GenerateCodeChallenge(_offlineCodeVerifier);
@@ -541,11 +541,11 @@ public async Task<bool> LoginAsync(CancellationToken cancellationToken = default
541541
offlineQueryParams["client_id"] = "OneWareStudio";
542542
offlineQueryParams["redirect_uri"] = redirectUri;
543543
offlineQueryParams["response_type"] = "code";
544-
offlineQueryParams["scope"] = "openid offline_access";
544+
offlineQueryParams["scope"] = "openid profile email offline_access";
545545
offlineQueryParams["code_challenge"] = offlineCodeChallenge;
546546
offlineQueryParams["code_challenge_method"] = "S256";
547547
offlineQueryParams["state"] = _offlineState;
548-
offlineQueryParams["prompt"] = "none";
548+
offlineQueryParams["prompt"] = "consent";
549549
string offlineAuthUrl = $"{authProviderBaseUrl}/protocol/openid-connect/auth?{offlineQueryParams}";
550550

551551
step1Response.Redirect(offlineAuthUrl);
@@ -586,6 +586,8 @@ await ExchangeCodeForTokensAsync(code2, authProviderBaseUrl, redirectUri,
586586
step2Response.Redirect($"{cloudHost}/");
587587
step2Response.KeepAlive = false;
588588
step2Response.Close();
589+
590+
return true;
589591
}
590592
catch (HttpListenerException) when (cancellationToken.IsCancellationRequested)
591593
{
@@ -609,17 +611,18 @@ await ExchangeCodeForTokensAsync(code2, authProviderBaseUrl, redirectUri,
609611
}
610612

611613
private async Task ExchangeCodeForTokensAsync(string code, string authProviderBaseUrl, string redirectUri,
612-
bool persistTokens = true, string? codeVerifierOverride = null)
614+
bool persistTokens = true, string? codeVerifierOverride = null, string? clientIdOverride = null)
613615
{
614616
try
615617
{
616618
var tokenEndpoint = $"{authProviderBaseUrl}/protocol/openid-connect/token";
617619
var usedCodeVerifier = codeVerifierOverride ?? _codeVerifier;
620+
var clientId = clientIdOverride ?? "OneWareStudio";
618621

619622
var request = new RestRequest(tokenEndpoint, Method.Post);
620623
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
621624
request.AddParameter("grant_type", "authorization_code");
622-
request.AddParameter("client_id", "OneWareStudio");
625+
request.AddParameter("client_id", clientId);
623626
request.AddParameter("code", code);
624627
request.AddParameter("redirect_uri", redirectUri);
625628
request.AddParameter("code_verifier", usedCodeVerifier);

0 commit comments

Comments
 (0)