Update migration to enable all scenarios out of the box
This commit is contained in:
parent
b865d58786
commit
8112557164
|
|
@ -1,6 +1,6 @@
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26815.2
|
||||
VisualStudioVersion = 15.0.26820.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0F647068-6602-4E24-B1DC-8ED91481A50A}"
|
||||
EndProject
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Identity.Service;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
|
|
@ -305,44 +306,95 @@ namespace IdentityOIDCWebApplicationSample.Identity.Data.Migrations
|
|||
column: "NormalizedUserName",
|
||||
unique: true);
|
||||
|
||||
// Seed client application
|
||||
var clientAppId = "4122031F-D3A2-4C1A-B25E-2A55B2A32FAC";
|
||||
var clientId = "56A33E6A-ADFE-47EA-BBFE-40F4AE4C55BA";
|
||||
migrationBuilder.Sql($@"INSERT INTO AspNetApplications (Id,ClientId,Name)
|
||||
VALUES (N'{clientAppId}',N'{clientId}',N'IdentityOIDCWebApplicationSample')");
|
||||
//migrationBuilder.InsertData(
|
||||
// table: "AspNetApplications",
|
||||
// columns: new[] { "Id", "ClientId", "Name" },
|
||||
// values: new object[,]
|
||||
// {
|
||||
// { clientAppId, clientId, "IdentityOIDCWebApplicationSample" }
|
||||
// });
|
||||
// Seed client applications
|
||||
var integratedClientClientId = "56A33E6A-ADFE-47EA-BBFE-40F4AE4C55BA";
|
||||
RegisterApplication(migrationBuilder,
|
||||
integratedClientClientId,
|
||||
"IdentityOIDCWebApplicationSample",
|
||||
new[] { ApplicationScope.OpenId.Scope },
|
||||
new[] { "urn:self:aspnet:identity:integrated" },
|
||||
new[] { "urn:self:aspnet:identity:integrated" });
|
||||
|
||||
var clientOpenIdScopeId = "7F4F91FE-87F5-41DC-B111-3DC5FC186E35";
|
||||
migrationBuilder.Sql($@"INSERT INTO AspNetScopes (Id,ApplicationId,Value)
|
||||
VALUES (N'{clientOpenIdScopeId}',N'{clientAppId}',N'{ApplicationScope.OpenId.Scope}')");
|
||||
//migrationBuilder.InsertData(
|
||||
// table: "AspNetScopes",
|
||||
// columns: new[] { "Id", "ApplicationId", "Value" },
|
||||
// values: new object[,]
|
||||
// {
|
||||
// { clientOpenIdScopeId, clientAppId, ApplicationScope.OpenId.Scope },
|
||||
// });
|
||||
var mobileAppId = "06D7C2FB-A66A-41AD-9509-77BDDFAB111B";
|
||||
RegisterApplication(migrationBuilder,
|
||||
mobileAppId,
|
||||
"MobileApplication",
|
||||
new[] { ApplicationScope.OpenId.Scope, ApplicationScope.OfflineAccess.Scope },
|
||||
new[] { "urn:ietf:wg:oauth:2.0:oob" },
|
||||
new[] { "urn:ietf:wg:oauth:2.0:oob" });
|
||||
|
||||
var clientRedirectUriId = "849B8050-0DEC-4A96-B234-8A08695A1526";
|
||||
var clientLogoutRedirectUriId = "9F24EA98-4375-4CE2-A37C-95832F19D75D";
|
||||
migrationBuilder.Sql($@"INSERT INTO AspNetRedirectUris (Id, ApplicationId, IsLogout, Value)
|
||||
VALUES (N'{clientRedirectUriId}',N'{clientAppId}','false',N'urn:self:aspnet:identity:integrated')");
|
||||
migrationBuilder.Sql($@"INSERT INTO AspNetRedirectUris (Id, ApplicationId, IsLogout, Value)
|
||||
VALUES (N'{clientLogoutRedirectUriId}',N'{clientAppId}','true',N'urn:self:aspnet:identity:integrated')");
|
||||
//migrationBuilder.InsertData(
|
||||
// table: "AspNetRedirectUris",
|
||||
// columns: new[] { "Id", "ApplicationId", "IsLogout", "Value" },
|
||||
// values: new object[,]
|
||||
// {
|
||||
// { clientRedirectUriId, clientAppId, false, "urn:self:aspnet:identity:integrated"},
|
||||
// { clientLogoutRedirectUriId, clientAppId, true, "urn:self:aspnet:identity:integrated" }
|
||||
// });
|
||||
var protectedApi = "6EA3533F-DD7B-4C34-AAAD-3C493B72D7A5";
|
||||
RegisterApplication(migrationBuilder,
|
||||
protectedApi,
|
||||
"ProtectedApi",
|
||||
new[] { "read" },
|
||||
new string[] { },
|
||||
new string[] { });
|
||||
|
||||
var spaClientId = "CDA53D17-6683-4EA7-B6D7-B6DB23E60DED";
|
||||
RegisterApplication(migrationBuilder,
|
||||
spaClientId,
|
||||
"SPA",
|
||||
new[] { ApplicationScope.OpenId.Scope },
|
||||
new[] { "https://localhost:44324/Spa.html" },
|
||||
new[] { "https://localhost:44324/Spa.html" });
|
||||
}
|
||||
|
||||
private void RegisterApplication(
|
||||
MigrationBuilder migrationBuilder,
|
||||
string clientId,
|
||||
string name,
|
||||
string[] scopes,
|
||||
string[] redirectUris,
|
||||
string[] logoutRedirectUris)
|
||||
{
|
||||
var clientAppId = Guid.NewGuid().ToString();
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetApplications",
|
||||
columns: new[] { "Id", "ClientId", "Name" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ clientAppId, clientId, name }
|
||||
});
|
||||
|
||||
var scopeValues = new object[scopes.Length, 3];
|
||||
|
||||
for (int i = 0; i < scopes.Length; i++)
|
||||
{
|
||||
scopeValues.SetValue(Guid.NewGuid().ToString(), i, 0);
|
||||
scopeValues.SetValue(clientAppId, i, 1);
|
||||
scopeValues.SetValue(scopes[i], i, 2);
|
||||
}
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetScopes",
|
||||
columns: new[] { "Id", "ApplicationId", "Value" },
|
||||
values: scopeValues);
|
||||
|
||||
var redirectUriValues = new object[redirectUris.Length + logoutRedirectUris.Length, 4];
|
||||
|
||||
for (var i = 0; i < redirectUris.Length; i++)
|
||||
{
|
||||
var clientRedirectUriId = Guid.NewGuid().ToString();
|
||||
redirectUriValues.SetValue(clientRedirectUriId, i, 0);
|
||||
redirectUriValues.SetValue(clientAppId, i, 1);
|
||||
redirectUriValues.SetValue(false, i, 2);
|
||||
redirectUriValues.SetValue(redirectUris[i], i, 3);
|
||||
}
|
||||
|
||||
for (var i = redirectUris.Length; i < redirectUris.Length + logoutRedirectUris.Length; i++)
|
||||
{
|
||||
var clientLogoutUriId = Guid.NewGuid().ToString();
|
||||
redirectUriValues.SetValue(clientLogoutUriId, i, 0);
|
||||
redirectUriValues.SetValue(clientAppId, i, 1);
|
||||
redirectUriValues.SetValue(true, i, 2);
|
||||
redirectUriValues.SetValue(logoutRedirectUris[i - redirectUris.Length], i, 3);
|
||||
}
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetRedirectUris",
|
||||
columns: new[] { "Id", "ApplicationId", "IsLogout", "Value" },
|
||||
values: redirectUriValues);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ namespace IdentityOIDCWebApplicationSample.Controllers
|
|||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Spa() => Redirect("Spa.html");
|
||||
|
||||
public IActionResult About()
|
||||
{
|
||||
ViewData["Message"] = "Your application description page.";
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"ClientId": "56A33E6A-ADFE-47EA-BBFE-40F4AE4C55BA"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-IdentityOIDCWebApplicationSample-71B323EE-A696-4709-9EA5-C93EFCD9E6FB;Trusted_Connection=True;MultipleActiveResultSets=true"
|
||||
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-IdentityOIDCWebApplicationSample-ABC3481D-5C0B-4474-955F-8298AC53AD25;Trusted_Connection=True;MultipleActiveResultSets=true"
|
||||
},
|
||||
"Logging": {
|
||||
"IncludeScopes": false,
|
||||
|
|
|
|||
|
|
@ -36,18 +36,22 @@
|
|||
<script class="pre">
|
||||
// The current application coordinates were pre-registered in a B2C tenant.
|
||||
var applicationConfig = {
|
||||
clientID: '4c0e3ab6-3bdc-4eca-80ab-89669d974e13',
|
||||
clientID: 'CDA53D17-6683-4EA7-B6D7-B6DB23E60DED',
|
||||
redirectUri: "https://localhost:44324/Spa.html",
|
||||
authority: "https://localhost:44324/tfp/IdentityService/signinsignup",
|
||||
b2cScopes: ["https://localhost/DFC7191F-FF74-42B9-A292-08FEA80F5B20/v2.0/spa/read"],
|
||||
b2cScopes: ["https://localhost/DFC7191F-FF74-42B9-A292-08FEA80F5B20/v2.0/ProtectedApi/read"], // <<issuer>>/<<resourceAppName>>/<<resourceAppScope>>.
|
||||
webApi: 'https://localhost:44324/Home/Contact',
|
||||
};
|
||||
</script>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
var clientApplication = new Msal.UserAgentApplication(applicationConfig.clientID, applicationConfig.authority, function (errorDesc, token, error, tokenType) {
|
||||
var clientApplication = new Msal.UserAgentApplication(
|
||||
applicationConfig.clientID,
|
||||
applicationConfig.authority,
|
||||
function (errorDesc, token, error, tokenType) {
|
||||
// Called after loginRedirect or acquireTokenPopup
|
||||
});
|
||||
}, { redirectUri: applicationConfig.redirectUri });
|
||||
|
||||
function login() {
|
||||
clientApplication.loginPopup(applicationConfig.b2cScopes).then(function (idToken) {
|
||||
|
|
|
|||
|
|
@ -29,26 +29,26 @@ namespace NativeWPFClient
|
|||
{
|
||||
InitializeComponent();
|
||||
// Local client
|
||||
//DataContext = new NativeWPFClientViewModel
|
||||
//{
|
||||
// BaseAddress = "https://localhost/",
|
||||
// RedirectUri = "urn:ietf:wg:oauth:2.0:oob",
|
||||
// Tenant = "IdentityService",
|
||||
// Policy = "signinsignup",
|
||||
// ClientId = "777f6733-a5ef-49d5-bc0a-877e89ed768b",
|
||||
// Scopes = "read"
|
||||
//};
|
||||
|
||||
DataContext = new NativeWPFClientViewModel
|
||||
{
|
||||
BaseAddress = "https://login.microsoftonline.com/",
|
||||
BaseAddress = "https://localhost:44324/",
|
||||
RedirectUri = "urn:ietf:wg:oauth:2.0:oob",
|
||||
Tenant = "jacalvarb2c.onmicrosoft.com",
|
||||
Policy = "B2C_1_signinsignup",
|
||||
ClientId = "42291769-0dc8-4497-9cbc-d3879783d6e7",
|
||||
Scopes = "https://jacalvarb2c.onmicrosoft.com/ProtectedApi/read"
|
||||
Tenant = "IdentityService",
|
||||
Policy = "signinsignup",
|
||||
ClientId = "06D7C2FB-A66A-41AD-9509-77BDDFAB111B",
|
||||
Scopes = "https://localhost/DFC7191F-FF74-42B9-A292-08FEA80F5B20/v2.0/ProtectedApi/read"
|
||||
};
|
||||
|
||||
// DataContext = new NativeWPFClientViewModel
|
||||
// {
|
||||
// BaseAddress = "https://login.microsoftonline.com/",
|
||||
// RedirectUri = "urn:ietf:wg:oauth:2.0:oob",
|
||||
// Tenant = "jacalvarb2c.onmicrosoft.com",
|
||||
// Policy = "B2C_1_signinsignup",
|
||||
// ClientId = "42291769-0dc8-4497-9cbc-d3879783d6e7",
|
||||
// Scopes = "https://jacalvarb2c.onmicrosoft.com/ProtectedApi/read"
|
||||
// };
|
||||
|
||||
ViewModel.Result = "Hit authorize to sign in";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue