Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts
Log In
Found the internet!
Create an account to follow your favorite communities and start taking part in conversations.
Posts
Communities

Posts about ASP.NET

Subreddit Icon
r/aspnetcore
6.2k members
News, posts, articles about ASP.NET Core (formerly ASP.NET 5)
Visit
Subreddit Icon
r/dotnet
131k members
.NET Community, if you are using C#, VB.NET, F#, or anything running with .NET... you are at the right place!
Visit
Subreddit Icon
r/csharp
224k members
Welcome to r/csharp
Visit
Subreddit Icon
r/programming
5.4m members
Computer Programming
Visit
r/learnprogramming
3.8m members
A subreddit for all questions related to programming in any language.
Visit
Subreddit Icon
r/webdev
1.6m members
A community dedicated to all things web development: both front-end and back-end. For more design-related questions, try /r/web_design.
Visit
Subreddit Icon
r/dotnetcore
11.8k members
Welcome to r/dotnetcore
Visit
Subreddit Icon
r/StarWarsEU
291k members
Welcome to the Star Wars Expanded Universe subreddit! We are primarily a source of discussion and news for anything involving the Star Wars Expanded Universe (Legends or Story Group Canon). If you're new, and want to learn more about the Expanded Universe, you can find a few links in the sidebar that may be helpful. Feel free to ask the community!
Visit
r/Blazor
12.6k members
Blazor is a framework for building Single Page Applications using C# where your application code can run either on the client in WebAssembly, or on the server.
Visit
Subreddit Icon
r/forhire
311k members
Some redditors are skilled professionals, some redditors need skilled professionals. Scroll down for general information and our rules. Please read through these carefully, as breaking them can be a bannable offense.
Visit
r/twitterbootstrapmvc
31 members
Development for ASP.NET MVC with Bootstrap made simple.
Visit
Subreddit Icon
r/learncsharp
12.9k members
Learn C# is about learning C#! Post your questions regardless of your experience level.
Visit
Subreddit Icon
r/Angular2
63.1k members
Angular is Google's open source framework for crafting high-quality front-end web applications. r/Angular2 exists to help spread news, discuss current developments and help solve problems. Welcome!
Visit
Subreddit Icon
r/CompTIA
172k members
From the "looking to get certified," to conversations/questions from current students, to certified and working professionals - this subreddit is dedicated to CompTIA certifications.
Visit
Subreddit Icon
r/cscareerquestions
1.0m members
A subreddit for those with questions about working in the tech industry or in a computer-science-related job.
Visit
Subreddit Icon
r/AZURE
117k members
The Microsoft Azure community subreddit
Visit
Subreddit Icon
r/fsharp
10.6k members
This group is for people interested in the F# language, the functional-first language targeting .NET, JavaScript, and WebAssembly. More info about the language can be found at https://fsharp.org
Visit
Subreddit Icon
r/reactjs
346k members
A community for learning and developing web applications using React by Facebook.
Visit
Subreddit Icon
r/AskProgramming
97.5k members
A subreddit for all your programming questions.
Visit
Subreddit Icon
r/ProgrammerHumor
3.0m members
Dedicated to humor and jokes relating to programmers and programming.
Visit
Subreddit Icon
r/netsec
475k members
/r/netsec is a community-curated aggregator of technical information security content. Our mission is to extract signal from the noise — to provide value to security practitioners, students, researchers, and hackers everywhere. ‎
Visit
r/angularjs
55.3k members
A community for the awesome MVC JS framework.
Visit
r/vuejs
93.8k members
Vue.js is a library for building interactive web interfaces. It provides data-reactive components with a simple and flexible API.
Visit
Subreddit Icon
r/ABPFramework
71 members
ABP is an open-source web application framework for ASP.NET Core. It is a complete infrastructure to create modern web applications. https://abp.io/
Visit
r/serverside
152 members
Tutorials, news, tips & tricks in server-side programming languages. Ruby, PHP, ASP.NET, Python, Go, Java, C, D and the rest...
Visit
Subreddit Icon
r/slavelabour
310k members
Get jobs done well below market rate. Any task (within reason) can be completed here for pay. Find casual online work. Earn a few dollars here and there completing small tasks. It will soon add up. Employers can outsource tasks instantly. Please use Old Reddit to see the full list of rules and sidebar to participate here.
Visit
Subreddit Icon
r/angular
29.3k members
Content specific to Angular. If you're looking for AngularJS or Angular 1 related information, check out r/AngularJS.
Visit
Subreddit Icon
r/EasyXLS
34 members
EasyXLSâ„¢ is the best .NET and Java Excel library to read, write or convert Microsoft Excel files, an Excel reporting tool for programmers, a library to export and import Excel files. File formats: XLSX, XLS, XLSM, XLSB, CSV, TXT, XML, HTML. - C# Excel library - VB.NET Excel library - PHP Excel library - Classic ASP Excel library - Java Excel library - ColdFusion Excel library - C++ Excel library - VB6 Excel library - VBScript Excel library - Python Excel library
Visit
Subreddit Icon
r/ProgrammingBuddies
47.3k members
A place for people to group up to learn and teach programming to each other.
Visit
321
321
82 comments
37
Subreddit Icon
•Posted by13 days ago
37
148 comments
43
59
Subreddit Icon
•Posted by11 days ago
59
96 comments
53
Subreddit Icon
•Posted by8 days ago
53
38 comments
29
Subreddit Icon
•Posted by5 days ago

Hello, I have an ASP.NET Core API with Identity and EF and SQL Server acting as IdentityStore. I also have Facebook authentication middleware set up like this:

services.AddAuthentication(o =>
{
    o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie()
.AddFacebook(fb =>
{
    fb.AppId = Configuration["FacebookAppId"];
    fb.AppSecret = Configuration["FacebookAppSecret"];
    fb.SaveTokens = true;
});

I implemented the Auth controller following this sample code from Microsoft.

            [HttpGet("{scheme}")]
	public async Task Get([FromRoute] string scheme)
	{
		var auth = await Request.HttpContext.AuthenticateAsync(scheme);
                    bool isNotAuthenticated = !auth.Succeeded
			|| auth?.Principal == null
			|| !auth.Principal.Identities.Any(id => id.IsAuthenticated)
			|| string.IsNullOrEmpty(auth.Properties.GetTokenValue("access_token"));
		if (!isNotAuthenticated)
		{
			// Not authenticated, challenge
			await Request.HttpContext.ChallengeAsync(scheme);
		}
		else
		{
			var claims = auth.Principal.Identities.FirstOrDefault()?.Claims;
			var email = string.Empty;
			email = claims?.FirstOrDefault(c => c.Type == System.Security.Claims.ClaimTypes.Email)?.Value;

			// Get parameters to send back to the callback
			var qs = new Dictionary<string, string>
			{
				{ "access_token", auth.Properties.GetTokenValue("access_token") },
				{ "refresh_token", auth.Properties.GetTokenValue("refresh_token") ?? string.Empty },
				{ "expires_in", (auth.Properties.ExpiresUtc?.ToUnixTimeSeconds() ?? -1).ToString() },
				{ "email", email }
			};

			// Build the result url
			var url = callbackScheme + "://#" + string.Join(
				"&",
				qs.Where(kvp => !string.IsNullOrEmpty(kvp.Value) && kvp.Value != "-1")
				.Select(kvp => $"{WebUtility.UrlEncode(kvp.Key)}={WebUtility.UrlEncode(kvp.Value)}"));

			// Redirect to final url
			Request.HttpContext.Response.Redirect(url);
		}
	}

If the user is not authenticated, the bool value "isNotAuthenticated" is true, meaning the controller challenges the user to complete the auth workflow with the given provider (in my case Facebook). If the challenge is completed successfully, the auth provider calls this same controller (as I've set it to be the callback URL) and this time the "isNotAuthenticated" value is "true", meaning we've successfully logged in the user via an external provider. This code works.

However what I cannot understand is how to "insert" this user's external identity into my IdentityStore (in the Identity database) so I can store the user info for other purposes.

Basically I guess the part that I'm missing is - how do I integrate the identity received by the external login as an IdentityUser in my app? Sorry if the question is not worded correctly - if something is unclear I will be happy to clarify in the comments.

Thanks

29
7 comments