IdentityServer4 Issues - identityserver4

I am creating a web API security using IdentityServer4. I installed the identityserver4 package by typing the following syntax in the console manager: Install-Package IdentityServer4 -Pre. It gets installed successfully. Now i cannot reference it in my project.
Here is my project.json code after installation:
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"IdentityServer4": "1.0.0-rc1-update2"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
]
}
So now i have created a client class with the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace LearningIdentityServer4.OAuth
{
public class Clients
{
public static IEnumerable<Client> Get()
{
return new[]
{
new Client
{
ClientId = "myApi",
ClientSecrets = new List<Secret>
{
new Secret("secret".Sha256())
},
ClientName = "My lovely Api",
Flow = Flows.ResourceOwner,
AllowedScope =
{
Constants.StandardScope.OpenId,
"read"
},
Enabled = true
}
};
}
}
}
So I get many errors. When I hover my mouse over let's say the first client, the only options i am getting is Add Package IdentityServer3 2.1.1
So how do i reference the IdentityServer4 instead of IdentityServer3 2.1.1
I would looking forward to hearing from you.
Thanks, Somad

Those frameworks are totally outdated.
To use identityserver4 you need to (at minimum) depend on netcoreapp 1.0 framework with some added dependancies. replace your frameworks in your project.json to the following:
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
Also see the samples. I assume either your tooling is outdated, or you are opening up an old project again. Lots of stuff has changed with ASP.NET Core.

Related

How do I solve CORS Policy error with .NET 6 and React?

I am trying to call an API in the frontend, but I get this error instead:
Access to XMLHttpRequest at 'http://localhost:5087/api/GetPlayerById/2' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Frontend is running on http://localhost:3000/ (React)
Backend is running on http://localhost:5087/ (.NET 6)
API works on Postman
API works on browser (Copy/Pasting the API on browser)
CORS error appears when I call the API in React
I already looked at many post on CORS policy but none seems to help me. My last attemp was referring to Enable Cross-Origin Requests (CORS) in ASP.NET Core.
Code so far (in .NET 6):
Program.cs
using tournament_manager_backend.Data;
using Microsoft.EntityFrameworkCore;
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(options =>
{
options.AddPolicy(name: MyAllowSpecificOrigins,
policy =>
{
policy.WithOrigins("http://localhost:3000");
});
});
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"));
});
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddScoped<IPlayerRepository, PlayerRepository>();
builder.Services.AddScoped<IMatchRepository, MatchRepository>();
var app = builder.Build();
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors(MyAllowSpecificOrigins);
app.UseAuthorization();
app.MapControllers();
app.Run();
appsettings.json
{
"ConnectionStrings": {
"DefaultConnection": "server=(localdb)\\ProjectModels;database=TournamentManager"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"Host": {
"CORS": "http://localhost:5087,http://localhost:3000"
}
}
launchSettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:19870",
"sslPort": 44328
}
},
"profiles": {
"tournament_manager_backend": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5087",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
}
}
}
}
I know there are a lot of questions on this topic already but I have already changed the code many times from different sources that if I were to refer them here, it will make this post too long. I did the best I can to give you as much details as possible so that I can seek effective guidance. I will appreciate anyone helping. Thanks!
The easiest solution is to include a proxy in the React server that you're using for development. In your package.json include:
"proxy": "http://localhost:5087/",
as part of the top level parameters (i.e., no parent). This creates a proxy through http://localhost:3000/ to your back end.
Note that this is for development. When you move to a "real" server you won't be using the React dev server for serving your front end code and there will likely be a different way to setup CORS.

app configuration appId is missing from Firebase Hosting reserved URL "/__/firebase/init.js" on localhost only

I recently started seeing an error on my localhost version of Firebase hosted website in Chrome:
Uncaught FirebaseError: Installations: Missing App configuration value: "appId" (installations/missing-app-config-values).
I'm not sure what has triggered this. I'm using the Firebase Hosting Reserved URL method to include the firebase config and it's had no issues until recently.
The config is loaded via <script src="/__/firebase/init.js"></script>.
This is the config file at that URL:
if (typeof firebase === 'undefined') throw new Error('hosting/init-error: Firebase SDK not detected. You must include it before /__/firebase/init.js');
var firebaseConfig = {
"projectId": "remotesoc...",
"databaseURL": "https://remotesoc...firebaseio.com",
"storageBucket": "remotesoc...appspot.com",
"locationId": "us-central",
"apiKey": "AIzaSyC3K7HT9- ... ",
"authDomain": "remotesoc...firebaseapp.com",
"messagingSenderId": "43697..."
};
if (firebaseConfig) {
firebase.initializeApp(firebaseConfig);
}
As you can see the "appId" value is missing. I'm almost certain this used to be there.
I've built and deployed the app multiple times which is listed as the way to ensure that Firebase has the correct config values for the project.
The app is definitely using the correct project, and has a reference to the hosting site in the firebase.json
{
"database": {
"rules": "database.rules.json"
},
"functions": {
"source": "functions"
},
"hosting": {
"site": "remotesoc...",
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
}
}
I've run >firebase init several times in an attempt to reset the CLI.
The deployed site has no missing config vars and is working perfectly this is only on localhost.
I could revert to using an included config file, however that negates the benefits of having the reserved URLs inject the values for you.
Any help would be appreciated.

Review App are not deployed automatically in Heroku

I'm trying to set a pipeline that automatically creates a review build for my create-react-app which I can review from GitHub.
This is my app.json file:
{
"name": "harry100-exercise",
"scripts": {
},
"env": {
},
"formation": {
"web": {
"quantity": 1
}
},
"addons": [
],
"buildpacks": [
{
"url": "heroku/nodejs"
}
]
}
I have created a pipeline and enabled auto deploying for the master branch.
But everytime I create a pull request on github, I have to manually click create review app on heroku to view the review app
Any help on this?
Make sure you don't have "Wait for CI to pass" checked on the Review Apps setting page for the pipeline you are editing.

how to handle client side react routing in loopback.js

I am using react with loopback. I wanted to integrate react code in loopback.
if i do these 3 steps
1)middleware.json - put this
"files": {
"loopback#static": {
"params":"$!../client"
}
},`
2)root.js
router.get('/');
3)front end code
"build": "react-scripts build && cp -r build/* ../client/",
That didopen my react site on localhost:3000 .Now issue is when i do this
i cant access my loopback on :3000/explorer
So my first question is in this scenario, how to access explorer.
But then i rolled it back , because i wanted to use loopback explorer again.
So, i deleted all these added code and explorer came back
but when i added it again
Now, i dont see my react code
I can still see explorer at http://localhost:3000/explorer/
if i go to http://localhost:3000/apphome
i see 404 error
Right now, my middleware.json file for loopback is
{
"initial:before": {
"loopback#favicon": {}
},
"initial": {
"compression": {},
"cors": {
"params": {
"origin": true,
"credentials": true,
"maxAge": 86400
}
},
"helmet#xssFilter": {},
"helmet#frameguard": {
"params": [
"deny"
]
},
"helmet#hsts": {
"params": {
"maxAge": 0,
"includeSubdomains": true
}
},
"helmet#hidePoweredBy": {},
"helmet#ieNoOpen": {},
"helmet#noSniff": {},
"helmet#noCache": {
"enabled": false
}
},
"session": {},
"auth": {},
"parse": {
"body-parser#json": {},
"body-parser#urlencoded": {
"params": {
"extended": true
}
}
},
"routes": {
"loopback#rest": {
"paths": [
"${restApiRoot}"
]
}
},
"files": {
"loopback#static": {
"params":"$!../client"
}
},
"final": {
"loopback#urlNotFound": {},
"./LoopbackUrlNotFoundCatch.js": {}
},
"final:after": {
"strong-error-handler": {}
}
}
root.js file
'use strict';
//router.get('/', server.loopback.status());
module.exports = function(server) {
// Install a `/` route that returns server status
var router = server.loopback.Router();
router.get('/');
server.use(router);
};
-edit
I made some changes. Now, i have react components showing, I can also see data when i use api routes. But, explorer is still missing.
middleware.json
"files": {
"loopback#static": [
{
"name": "publicPath",
"paths": ["/"],
"params": "$!../client"
},
{
"name": "reactRouter",
"paths": ["*"],
"params": "$!../client/index.html",
"optional":true
}
]
},
I have also changed named of root.js to root_something.js . In documentation, its written, no need of root.js
First of all you Should be create react app in an other director like
Root ->
|-- client // emply
|-- clint_src // react app
and getting build react app and copy build files to client
now you should be remove server.loopback.status() in "server/boot/root.js" file
Example:
router.get('/', server.loopback.status());
To :
module.exports = function(server) {
// Install a `/` route that returns server status
var router = server.loopback.Router();
router.get('/');
server.use(router);
};
after that you need say to loopback middleware which file should be load in your path
go to middlware /server/middleware.json and replace blow code to "files": {}
"files": {
"loopback#static": [
{
"paths": ["/"],
"params": "$!../client"
},
{
"paths": ["*"],
"params": "$!../client"
}
]
},
on "paths": ["*"], all route will be open react file exeption the "/api" and "explorer" so you should be handle page notfound inside react app
Hope This was help full
Good Luck
I suspect React's default service worker intercepts and tries to cache /explorer. It skips urls prefixed with __ so this might fix the need to clear browser:
In component-config.json:
{ "loopback-component-explorer": {
"mountPath": "/__explorer" }}
Then access explorer at /__explorer.
As the instructions for adding a GUI to a loopback application state, you need to remove the root.js '/' route completely, by either renaming the root.js file to something without a .js extension, or deleting the file altogether.
$ rm root.js
### or, you can do this
$ mv root.js root.js.old
In the loopback 3 server configuration, the client folder has to be setup as a middleware route in middleware.json, like so:
"files": {
"loopback#static": {
"params": "$!../client"
}
},
Now, your client application is served from the /client folder, and by default the static files are served with Express -- so, it will look for index.html when you hit localhost:3000/

ExtJS 6 - Unable to create Native app using command 'sencha app build native'

I am using sencha cmd 6 and trying to build native app with help of -
https://docs.sencha.com/cmd/6.x/cordova_phonegap.html
I have generated Ext 6+ universal application using following command:
sencha -sdk /path/to/Framework generate app MyApp /path/to/MyApp
Then I have added following code in app.json -
"builds": {
"classic": {
"toolkit": "classic",
"theme": "theme-triton",
"sass": {
// "save": "classic/sass/save.json"
}
},
"native": {
"toolkit": "modern",
"theme": "theme-cupertino",
"packager": "phonegap",
"phonegap": {
"config": {
"platforms": "ios android",
"id": "com.mydomain.MyApp"
}
}
}
}
But after running sencha app build android, I am getting following exception -
BUILD FAILED
java.lang.NullPointerException
at org.a
pache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
Also as per suggestion in Developing a PhoneGap application from sencha doc, i have modified app.json with following code -
"builds": {
"native": {
"packager": "phonegap",
"phonegap" : {
"config": {
"platforms": "ios android",
"id": "com.mydomain.MyApp"
}
}
}
}
But after this, following exception is coming on my console -
Failed to resolve dependency Ext.app.Application for file MyApp.Application
BUILD FAILED
com.sencha.exceptions.ExNotFound: Unknown definition for dependency : Ext.app.Application
I know this is a late answer, but it might help someone else landing on this page.
To resolve the dependency, we need to include the toolkit and theme in our build profile:
"native": {
"toolkit": "modern",
"theme": "theme-cupertino",
"packager": "cordova",
"cordova": {
"config": {
"platforms": "android",
"id": "com.mydomain.NewApp"
}
}
}
In context, the build profile should look like:
Please find the answer to this question on following link -
https://www.sencha.com/forum/showthread.php?304530-Unable-to-create-Native-app-using-command-sencha-app-build-native

Resources