@@ -170,6 +170,14 @@ public async Task<IActionResult> Github()
170
170
return Redirect ( GithubrUrl ) ;
171
171
}
172
172
173
+ [ HttpGet ]
174
+ public async Task < IActionResult > Reddit ( )
175
+ {
176
+ string RedditUrl = $ "https://github.com/login/oauth/authorize?scope=identity&client_id={ _oauthConfig . Value . Reddit . client_id } &response_type=core&state={ Guid . NewGuid ( ) . ToString ( ) } &redirect_uri=https://{ this . Request . Host } /Auth/RedditCallback&duration=temporary";
177
+ return Redirect ( RedditUrl ) ;
178
+ }
179
+
180
+
173
181
[ HttpGet ]
174
182
public async Task < IActionResult > GoogleCallback ( [ FromQuery ] IDictionary < string , string > query )
175
183
{
@@ -356,6 +364,29 @@ public async Task<IActionResult> GithubCallback([FromQuery]IDictionary<string, s
356
364
return Redirect ( "/" ) ;
357
365
}
358
366
367
+ [ HttpGet ]
368
+ public async Task < IActionResult > RedditCallback ( [ FromQuery ] IDictionary < string , string > query )
369
+ {
370
+ if ( query [ "code" ] == null )
371
+ {
372
+ TempData [ "info" ] = "Link via Reddit failed. Try again later." ;
373
+ return Redirect ( "/" ) ;
374
+ }
375
+
376
+ Dictionary < string , string > parameters = new Dictionary < string , string > ( ) ;
377
+ parameters [ "code" ] = query [ "code" ] ;
378
+ parameters [ "redirect_uri" ] = $ "https://{ this . Request . Host } /Auth/RedditCallback";
379
+
380
+
381
+ Dictionary < string , string > headers = new Dictionary < string , string > ( ) ;
382
+ // TODO: client_id:client_secret in b64
383
+ headers . Add ( "Authorization" , $ "Basic { WIP } ") ;
384
+
385
+ RedditToken userToken = await _post < RedditToken > ( "https://www.reddit.com/api/v1/access_token" , parameters ) ;
386
+
387
+ return Redirect ( "/" ) ;
388
+ }
389
+
359
390
public async Task < T > _post < T > ( string path , Dictionary < string , string > body , Dictionary < string , string > headers = null )
360
391
{
361
392
HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Post , path ) ;
@@ -414,6 +445,8 @@ public class GithubToken
414
445
public string scope { get ; set ; }
415
446
}
416
447
448
+ public class RedditToken : GithubToken { }
449
+
417
450
public class GithubUserInfo
418
451
{
419
452
public string avatar_url { get ; set ; }
0 commit comments