-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Server, Client] Add Free Vote A mechanism that allows avatars in neighborhoods without elections to vote in an ongoing election of their choosing. * [Server] Free Vote, Github Releases, Restore Lot Tool, Test Utils Still need to fix an issue with the unauthenticated disconnect. * [Server] Improvements, Account Lockout - Too many failed password attempts can now cause an account lockout. - More reasonable CORS policy that doesn't spam warnings. * [UI] Add Free Vote Confirmation Text
- Loading branch information
1 parent
01aea6f
commit 21cea91
Showing
70 changed files
with
1,305 additions
and
136 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
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
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
79 changes: 79 additions & 0 deletions
79
TSOClient/FSO.Server.Api.Core/Controllers/GithubController.cs
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,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Cryptography; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Cors; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Octokit; | ||
|
||
namespace FSO.Server.Api.Core.Controllers | ||
{ | ||
[EnableCors] | ||
[ApiController] | ||
public class GithubController : ControllerBase | ||
{ | ||
readonly GitHubClient client = | ||
new GitHubClient(new ProductHeaderValue(Api.INSTANCE.Github.AppName), new Uri("https://github.com/")); | ||
|
||
private string StoredToken; | ||
private static string CSRF; | ||
|
||
// GET: /<controller>/ | ||
[HttpGet] | ||
[Route("github/")] | ||
public IActionResult Index() | ||
{ | ||
if (Api.INSTANCE.Github == null) return NotFound(); | ||
if (Api.INSTANCE.Github.AccessToken != null) return NotFound(); | ||
|
||
return Redirect(GetOauthLoginUrl()); | ||
} | ||
|
||
[HttpGet] | ||
[Route("github/callback")] | ||
public async Task<IActionResult> Callback(string code, string state) | ||
{ | ||
if (Api.INSTANCE.Github == null) return NotFound(); | ||
if (Api.INSTANCE.Github.AccessToken != null) return NotFound(); | ||
|
||
if (!String.IsNullOrEmpty(code)) | ||
{ | ||
var expectedState = CSRF; | ||
if (state != expectedState) throw new InvalidOperationException("SECURITY FAIL!"); | ||
//CSRF = null; | ||
|
||
var token = await client.Oauth.CreateAccessToken( | ||
new OauthTokenRequest(Api.INSTANCE.Github.ClientID, Api.INSTANCE.Github.ClientSecret, code) | ||
{ | ||
RedirectUri = new Uri("http://localhost:80/github/callback") | ||
}); | ||
StoredToken = token.AccessToken; | ||
} | ||
|
||
return Ok(StoredToken); | ||
} | ||
|
||
private string GetOauthLoginUrl() | ||
{ | ||
var rngCsp = new RNGCryptoServiceProvider(); | ||
string csrf = ""; | ||
var random = new byte[24]; | ||
rngCsp.GetBytes(random); | ||
for (int i=0; i<24; i++) | ||
{ | ||
csrf += (char)('?' + random[i]/4); | ||
} | ||
CSRF = csrf; | ||
|
||
// 1. Redirect users to request GitHub access | ||
var request = new OauthLoginRequest(Api.INSTANCE.Github.ClientID) | ||
{ | ||
Scopes = { "admin:org", "repo" }, | ||
State = csrf | ||
}; | ||
var oauthLoginUrl = client.Oauth.GetGitHubLoginUrl(request); | ||
return oauthLoginUrl.ToString(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.