-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
23,833 additions
and
41 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
41 changes: 41 additions & 0 deletions
41
Samples/net46/CSharp/AspNetSamples/CoreDemo/Controllers/HomeController.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,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using CoreDemo.Models; | ||
using LinqToTwitter; | ||
|
||
namespace CoreDemo.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
public IActionResult Index() | ||
{ | ||
if (!new SessionStateCredentialStore(HttpContext.Session).HasAllCredentials()) | ||
return RedirectToAction("Index", "OAuth"); | ||
|
||
return View(); | ||
} | ||
|
||
public IActionResult About() | ||
{ | ||
ViewData["Message"] = "Your application description page."; | ||
|
||
return View(); | ||
} | ||
|
||
public IActionResult Contact() | ||
{ | ||
ViewData["Message"] = "Your contact page."; | ||
|
||
return View(); | ||
} | ||
|
||
public IActionResult Error() | ||
{ | ||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
Samples/net46/CSharp/AspNetSamples/CoreDemo/Controllers/OAuthController.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,69 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using LinqToTwitter; | ||
using Microsoft.AspNetCore.Http.Extensions; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace CoreDemo.Controllers | ||
{ | ||
public class OAuthController : Controller | ||
{ | ||
readonly IConfiguration configuration; | ||
|
||
public OAuthController(IConfiguration configuration) | ||
{ | ||
this.configuration = configuration; | ||
} | ||
|
||
public ActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
|
||
public async Task<ActionResult> Begin() | ||
{ | ||
//var auth = new MvcSignInAuthorizer | ||
var auth = new MvcAuthorizer | ||
{ | ||
CredentialStore = new SessionStateCredentialStore(HttpContext.Session) | ||
{ | ||
ConsumerKey = configuration["Twitter:ConsumerKey"], | ||
ConsumerSecret = configuration["Twitter:ConsumerSecret"] | ||
} | ||
}; | ||
|
||
string twitterCallbackUrl = Request.GetDisplayUrl().Replace("Begin", "Complete"); | ||
return await auth.BeginAuthorizationAsync(new Uri(twitterCallbackUrl)); | ||
} | ||
|
||
public async Task<ActionResult> Complete() | ||
{ | ||
var auth = new MvcAuthorizer | ||
{ | ||
CredentialStore = new SessionStateCredentialStore(HttpContext.Session) | ||
}; | ||
|
||
await auth.CompleteAuthorizeAsync(new Uri(Request.GetDisplayUrl())); | ||
|
||
// This is how you access credentials after authorization. | ||
// The oauthToken and oauthTokenSecret do not expire. | ||
// You can use the userID to associate the credentials with the user. | ||
// You can save credentials any way you want - database, | ||
// isolated storage, etc. - it's up to you. | ||
// You can retrieve and load all 4 credentials on subsequent | ||
// queries to avoid the need to re-authorize. | ||
// When you've loaded all 4 credentials, LINQ to Twitter will let | ||
// you make queries without re-authorizing. | ||
// | ||
//var credentials = auth.CredentialStore; | ||
//string oauthToken = credentials.OAuthToken; | ||
//string oauthTokenSecret = credentials.OAuthTokenSecret; | ||
//string screenName = credentials.ScreenName; | ||
//ulong userID = credentials.UserID; | ||
// | ||
|
||
return RedirectToAction("Index", "Home"); | ||
} | ||
} | ||
} |
Oops, something went wrong.