|
1 | 1 | using System.Diagnostics; |
2 | 2 | using System.Net.Http.Headers; |
| 3 | +using System.Net.Http.Json; |
3 | 4 | using System.Text; |
4 | 5 | using System.Text.Json; |
5 | 6 | using System.Web; |
@@ -70,29 +71,24 @@ public static async Task<IActionResult> HandleOAuthRedirection(Uri response) |
70 | 71 | var responseMessage = await client.SendAsync(request); |
71 | 72 | responseMessage.EnsureSuccessStatusCode(); |
72 | 73 |
|
73 | | - var responseJson = await responseMessage.Content.ReadAsStringAsync(); |
74 | | - |
75 | | - return new ContentResult() |
| 74 | + var responseContent = await responseMessage.Content.ReadFromJsonAsync<OAuthResponse>(new JsonSerializerOptions() |
76 | 75 | { |
77 | | - StatusCode = 200, |
78 | | - ContentType = "application/json", |
79 | | - Content = responseJson |
80 | | - }; |
81 | | - //var responseContent = JsonSerializer.Deserialize<OAuthResponse>(responseJson); |
| 76 | + DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull |
| 77 | + }); |
82 | 78 |
|
83 | | - //if (!responseContent!.IsSuccess) |
84 | | - //{ |
85 | | - // return new ContentResult() { StatusCode = 500, ContentType = "text/plain", Content = $"There was a problem authenticating with Notion. Please try again later.\n\n{responseMessage.StatusCode}\n{responseContent.Error}\n{responseContent.ErrorDescription}" }; |
86 | | - //} |
| 79 | + if (!responseContent!.IsSuccess) |
| 80 | + { |
| 81 | + return new ContentResult() { StatusCode = 500, ContentType = "text/plain", Content = $"There was a problem authenticating with Notion. Please try again later.\n\n{responseMessage.StatusCode}\n{responseContent.Error}\n{responseContent.ErrorDescription}" }; |
| 82 | + } |
87 | 83 |
|
88 | | - //var responseUrl = $"cmdpalnotionext://oauth_redirect_uri/?access_token={responseContent.AccessToken}&bot_id={responseContent.BotId}"; |
| 84 | + var responseUrl = $"cmdpalnotionext://oauth_redirect_uri/?access_token={responseContent.AccessToken}&bot_id={responseContent.BotId}"; |
89 | 85 |
|
90 | | - //return new ContentResult() |
91 | | - //{ |
92 | | - // Content = String.Format(successMessage, responseUrl), |
93 | | - // ContentType = "text/html", |
94 | | - // StatusCode = 200 |
95 | | - //}; |
| 86 | + return new ContentResult() |
| 87 | + { |
| 88 | + Content = String.Format(successMessage, responseUrl), |
| 89 | + ContentType = "text/html", |
| 90 | + StatusCode = 200 |
| 91 | + }; |
96 | 92 | } |
97 | 93 | catch (HttpRequestException ex) |
98 | 94 | { |
|
0 commit comments