-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's finally here 🥲
- Loading branch information
Showing
10 changed files
with
236 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Azure.Security.KeyVault.Secrets; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace SeattleCarsInBikeLanes.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class ThreadsController : ControllerBase | ||
{ | ||
private readonly HttpClient httpClient; | ||
private readonly string redirectUri; | ||
|
||
public ThreadsController(IWebHostEnvironment environment, | ||
HttpClient httpClient, | ||
SecretClient secretClient) | ||
{ | ||
this.httpClient = httpClient; | ||
|
||
if (environment.IsDevelopment()) | ||
{ | ||
redirectUri = "https://localhost:7152/threadsredirect"; | ||
} | ||
else | ||
{ | ||
redirectUri = "https://seattle.carinbikelane.com/threadsredirect"; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function displayError(errorMessage) { | ||
const errorElement = document.createElement('h1'); | ||
errorElement.append(errorMessage); | ||
document.getElementsByTagName('body')[0].append(errorElement); | ||
} | ||
|
||
const url = new URL(window.location.href); | ||
if (url.searchParams.has('code')) { | ||
fetch(`api/Threads/Redirect?code=${url.searchParams.get('code')}`, { | ||
method: 'POST' | ||
}) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error(`Failed to get access token from Threads ${response}`); | ||
} | ||
|
||
return response.json(); | ||
}) | ||
.then(response => { | ||
localStorage.setItem('threadsAccessToken', response.accessToken); | ||
localStorage.setItem('threadsRefreshToken', response.refreshToken); | ||
localStorage.setItem('threadsExpiresAt', response.expiresAt); | ||
window.location.href = '/'; | ||
}) | ||
.catch(error => { | ||
displayError(error.message); | ||
}); | ||
} else { | ||
displayError('Redirect failed, no code from Threads'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Threads Redirect</title> | ||
</head> | ||
<body> | ||
<script src="js/threads-redirect.js"></script> | ||
</body> | ||
</html> |