Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Farrell xximjasonxx

View GitHub Profile
View ctx.cs
public Class1
{
public Class1(DbContextOptions<MyContext> options) : base(options)
{
if (configuration["Env"] == "Cloud")
{
var conn = (Microsoft.Data.SqlClient.SqlConnection)Database.GetDbConnection();
conn.AccessToken = (new Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProvider()).GetAccessTokenAsync("https://database.windows.net/").Result;
}
View auth_final.cs
[HttpPost]
public IActionResult Login([FromForm]LoginFormViewModel viewModel)
{
var authClient = new AuthenticationApiClient("<domain>.auth0.com");
var authUrl = authClient.BuildAuthorizationUrl()
.WithClient("<client id>")
.WithResponseType(AuthorizationResponseType.Code)
.WithConnection("Username-Password-Authentication")
.WithRedirectUrl("https://localhost:5001/home/callback")
.WithScope("openid offline_access")
View codeview.cshtml
@{
ViewData["Title"] = "Code Page";
}
<div class="text-center" style="width: 500px">
@CustomContext.AuthCode
<hr />
@CustomContext.RefreshToken
<hr />
@CustomContext.IdToken
View context.cs
namespace Auth0LoginCustom
{
public static class CustomContext
{
public static string AuthCode;
public static string AccessToken;
public static string RefreshToken;
public static string IdToken;
}
View callback2.cs
[HttpGet]
public async Task<IActionResult> Callback([FromQuery]string code)
{
var authClient = new AuthenticationApiClient("<domain>.auth0.com");
var tokenResponse = await authClient.GetTokenAsync(new AuthorizationCodeTokenRequest
{
RedirectUri = "https://localhost:5001/home/auth_callbabck",
Code = code,
ClientId = "<your client id>",
ClientSecret = "<your client secret>"
View callback.cs
[HttpGet]
public async Task<IActionResult> Callback([FromQuery]string code)
{
return Ok();
}
View login2.cs
[HttpPost]
public IActionResult Login([FromForm]LoginFormViewModel viewModel)
{
var authClient = new AuthenticationApiClient("<your domain>.auth0.com");
var authUrl = authClient.BuildAuthorizationUrl()
.WithClient("<your client id>")
.WithResponseType(AuthorizationResponseType.Code)
.WithConnection("Username-Password-Authentication")
.WithRedirectUrl("https://localhost:5001/home/callback")
.WithScope("openid offline_access")
View login1.cs
[HttpPost]
public IActionResult Login([FromForm]LoginFormViewModel viewModel)
{
return Ok();
}
View home.cshtml
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
@using (Html.BeginForm("Login", "Home", FormMethod.Post))
{
<input type="submit" value="Login" />
}
</div>
View secretcontroller.cs
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
namespace KeyVaultTest.Controllers
{
You can’t perform that action at this time.