IdentityServer4 Version="4.1.1" MTLS configuration services.AddAuthentication().AddCertificate not working - identityserver4

Problem with Startup.cs setup, according to documentation I should add
services.AddAuthentication()
.AddCertificate(options =>
{
options.AllowedCertificateTypes = CertificateTypes.All;
options.RevocationMode = X509RevocationMode.NoCheck;
});
But I got error:
'AuthenticationBuilder' does not contain a definition for
'AddCertificate' and there is no extension method 'AddCertificate'.
In samples code setup IdentityServer(HOST)/ConsoleMTLSClient it works .

You have to add the Microsoft.AspNetCore.Authentication.Certificate NuGet package.

Related

firebase cloud functions: cannot read property 'environment' of undefined

am getting this error while I'm trying to deploy to a new firebase project using
firebase deploy --only functions command. I have two projects in use, one dev and one prod, I was working on prod and deploy worked well now too but when I added this project dev the deploying keeps working well in prod but in this new project dev no. I instead get this error:
Error: Error occurred while parsing your function triggers.
TypeError: Cannot read property 'environment' of undefined
at Object. (/home/projectId/Bitbucket/project-backend/functions/lib/db.js:6:35)
I added the key and eveything in cert/dev/firebase-dev.json in order to work.
The file db.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.db = void 0;
const admin = require("firebase-admin");
const functions = require("firebase-functions");
const dir = functions.config().app.environment;
const certFile = `firebase-${dir}.json`;
//using admin SDK
const serviceAccount = require(__dirname + `/../cert/${dir}/${certFile}`);
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
.....
Any Idea? Thanks.
Since the error is cannot read property 'environment' of undefined and in your code we see
const dir = functions.config().app.environment;
the error seems to come from the environment configuration.
You should double check that the environment configuration is correctly set in the dev environment/project.
For that, you should use the firebase functions:config:get CLI command, as explained in the doc.

Microsoft Android application is not matching the signature hash with the application reply URI

Goal: Use the MS Identity application that was created by Microsoft and try to tailor the application according to our needs.
Issue The android application is not matching the signature hash with the Applications' Reply URI.
Configuration Values
Signature Hash: ga0RGNYHvNM5d0SLGQfpQWAPGJ8=
Redirect URI: msauth://com.azuresamples.msalandroidapp/ga0RGNYHvNM5d0SLGQfpQWAPGJ8%3D
Android:host: com.azuresamples.msalandroidapp
Android Scheme: msauth
Logs and Screenshots
Logs show: The redirect URI in the configuration file doesn't match with the one generated with package name and signature hash.
Screenshot of the error in the Android Emulator
Methods Tried
Tried to fix this by changing the android:path value to /ga0RGNYHvNM5d0SLGQfpQWAPGJ8%3D however got this message from the UI:
Screenshot of the update android:path value
Tried to change the Reply URI directly from Azure Portal, but was not able to
Tried changing the Redirect URI in the android code to msauth://com.azuresamples.msalandroidapp/ga0RGNYHvNM5d0SLGQfpQWAPGJ8%3D but that gave the same error
The default library in the code was 1.2, changed it to 1.5+ in gradle and still it didnt work.
Configuration Files
auth_config_single_account.json
"client_id" : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"authorization_user_agent" : "DEFAULT",
"redirect_uri" : "msauth://com.azuresamples.msalandroidapp/ga0RGNYHvNM5d0SLGQfpQWAPGJ8%3D",
"account_mode" : "SINGLE",
"broker_redirect_uri_registered": true,
"authorities" : [
{
"type": "AAD",
"authority_url": "https://login.microsoftonline.com/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}
]
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.azuresamples.msalandroidapp">
...
<intent-filter>
...
<data
android:host="com.azuresamples.msalandroidapp"
android:path="/ga0RGNYHvNM5d0SLGQfpQWAPGJ8="
android:scheme="msauth" />
</intent-filter>
...
</manifest>
Build-Gradle:app
...
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.appcompat:appcompat:$rootProject.ext.appCompatVersion"
implementation "com.google.android.material:material:$rootProject.ext.materialVersion"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.android.volley:volley:1.1.1'
if (findProject(':msal') != null) {
// For developer team only.
localImplementation project(':msal')
externalImplementation 'com.microsoft.identity.client:msal:1.5.+'
}
else {
// Downloads and Builds MSAL from maven central.
implementation 'com.microsoft.identity.client:msal:1.5.+'
}
}
Update
Was trying to avoid this but I have updated my keystore using the debug.keystore that microsoft provides and it works, however this is not solution for production environments. What are the steps I need to take for this to work in the production environment.
Not sure if it will be a relevant answer, but will share my experience.
At some point I run into the same issue, dig into the library and figured out how hash is calculated there. It was something like this (I have translated it into kotlin):
try {
val info = packageManager.getPackageInfo(
packageName,
PackageManager.GET_SIGNATURES
)
for (signature in info.signatures) {
val md = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
val hash = Base64.encodeToString(
md.digest(),
Base64.DEFAULT
)
Log.d("KeyHash", "KeyHash:$hash")
}
} catch (e: PackageManager.NameNotFoundException) {
Log.d("KeyHash", e.toString())
} catch (e: NoSuchAlgorithmException) {
}
The value calculated this way didn't match the value from running this command:
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64
But it was the one that msal library expects to get. Same happened on release signature. I haven't yet investigated the reason (maybe I did something wrong), but for now I'm using signature hash got from the first method, and it works fine.
This is Dome from the MSAL Android team.
If you want to use your own keystore, you will have to register your own application.
com.azuresamples.msalandroidapp was only registered with the signature hash of the provided debug.keystore.
Please let me know if you have any other question. You can also leave a question in our GitHub repository as well (we're constantly monitoring that one).
I tried with cmd and keytool but not get success. Please Try this code to generate key hash programmatically in you code.
String packageName = getApplicationContext().getPackageName();
try {
PackageInfo info = getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
sha1Singature = new String(Base64.encode(md.digest(), 0));
//String something = new String(Base64.encodeBytes(md.digest()));
Log.e(AppConstants.TAG, sha1Singature);
}
} catch (PackageManager.NameNotFoundException e1) {
Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
Log.e("exception", e.toString());
}
and then you set this Signature hash to Azure portal.

React-native-camera error when compiling android

I tried to upgrade my react native project to the newest version (0.59.2). Unfortunately, now when trying to run react-native run-android im getting this error:
Could not determine the dependencies of task ':app:preDebugBuild'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
> Could not resolve project :react-native-camera.
Required by:
project :app
> Cannot choose between the following variants of project :react-native-camera:
- generalDebugRuntimeElements
- mlkitDebugRuntimeElements
All of them match the consumer attributes:
- Variant 'generalDebugRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'generalDebug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Found react-native-camera 'general' but wasn't required.
- Variant 'mlkitDebugRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'mlkitDebug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Found react-native-camera 'mlkit' but wasn't required.
I have already tried to create a new project however this results in the same error.
Reinstalling the node modules didn't help either.
On iOS it works fine.
Insert the following lines in android/app/build.gradle
android {
...
defaultConfig {
...
missingDimensionStrategy 'react-native-camera', 'general' <-- insert this line
}
}
Please insert the following line in android/app/build.gradle inside defaultConfig block either
missingDimensionStrategy 'react-native-camera', 'general'
or
missingDimensionStrategy 'react-native-camera', 'mlkit'
Add jitpack to android/build.gradle
allprojects {
repositories {
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
}
Complete guide
Could not resolve project :react-native-camera. on Android
Hope this helps.
Step 1:
Change the class path in android/build.gradle in dependencies tag to this:
classpath 'com.android.tools.build:gradle:3.3.0'
Step:2:
Change the gradle version in android/gradle/wrapper/gradle-wrapper.properties to this:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
Step 3:
In the android/app/build.gradle add this at the top:
defaultConfig {
missingDimensionStrategy 'react-native-camera', 'general'
}
}
Step 4:
Also add these two lines:
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
Camera works now.
It is simple to resolve by adding missingDimensionStrategy attribute in defaultConfig tag in android/app/build.gradle.
android {
...
defaultConfig {
...
missingDimensionStrategy 'react-native-camera', 'general'
}
}
If you are still having the same issue then you have to do the following steps.
Ensure that your gradle build tool version is greater than 3.3.0. You can use 3.4.1 for this purpose. Change the gradle build tool version from android/build.gradle file buildscript dependencies attributes.
buildscript {
...
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")
}
}
Also have to change the gradle wrapper to 4.4 or later. You can change the gradle version in android/gradle/wrapper/gradle-wrapper.properties to this
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Finally add the following lines in repositories tag of android/build.gradle
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }

facebookConnectPlugin is not defined (ngCordova, Ionic app)

I'm trying to add native fb connect to my ionic app.
I'm using:
- Ionic
- ngCordova
- http://ngcordova.com/docs/plugins/facebook/
This is my code:
angular.module('starter.controllers', ['ngCordova'])
.config(function($cordovaFacebookProvider) {
var appID = 123456789;
var version = "v2.0"; // or leave blank and default is v2.0
$cordovaFacebookProvider.browserInit(appID, version);
})
Which leads to this error >
Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to:
Error: [$injector:modulerr] Failed to instantiate module starter.controllers due to:
ReferenceError: facebookConnectPlugin is not defined
at browserInit (http://localhost:8100/lib/ngCordova/dist/ng-cordova.js:1576:7)
at http://localhost:8100/js/controllers.js:6:30
at Object.invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11994:17)
at runInvokeQueue (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11900:35)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:11909:11
at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:8147:20)
at loadModules (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11890:5)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:11907:40
at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:8147:20)
at loadModules (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11890:5)
Tried a couple of things but without any positive result:
- When I build it and run it on my device the app displays a blank screen
Tried the normal cordova js code:
Changed $cordovaFacebookProvider to $cordovaFacebook (based on this thread:
forum.ionicframework.com/t/unknown-provider-cordovaprovider/13305/3
And this is a another related thread, but doesn't help me thought..
forum.ionicframework.com/t/does-ng-crodova-has-facebook-login/9163
I already have a prototype working with the fb auth in the in-app-browser. But I really want to have a native fb connect functionality.
i found a way to resolve this issue.
Thanks to this thread : https://github.com/driftyco/ng-cordova/issues/446
and this tutorial : https://github.com/Wizcorp/phonegap-facebook-plugin/blob/master/platforms/browser/README.md
1st step : Don't forget the <div id="fb-root"></div> after ur body.
2nd step : I added facebookConnectPlugin to my bower dependencies
See my bower.json :
"dependencies": {
"angular-google-maps": "~2.0.13",
"google-map": "~0.4.1",
"facebook-connect-plugin": "https://cdn.rawgit.com/Wizcorp/phonegap-facebook-plugin/master/facebookConnectPlugin.js"
}
See my app.config + code to init:
app.config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider, $animateProvider, $httpProvider, $cordovaFacebookProvider) {
var appID = 597135743751760;
var version = "v2.0"; // or leave blank and default is v2.0
$cordovaFacebookProvider.browserInit(appID, version);
$cordovaFacebookProvider call facebookConnectPlugin()
3th step : After changing this dependencies, don't forget to call bower update from ur CLI.
4th step : Include the new facebookblablabla.js in your index.html.
it can be
<script src='bower_components/facebook-connect-plugin/index.js'></script>
for me it was
<script src='lib/facebook-connect-plugin/index.js'></script>
5th step : add in the Valid OAuth redirect URIs field at your Facebook App :
http://static.ak.facebook.com/connect/xd_arbiter/
Hope it works for you :) !
My answer is not providing a solution for your issue but an advice.
Why using facebook Cordova when you can use HelloJS?
faceBook Cordova is platform dependant, much slower as it runs cordova true node.js and not evolutive.
HelloJS permits to integer various Oauth2 authentication very easily including, facebook / google / twitter / instagram ...
Without to tell that the compilation for facebook cordova is very tricky with the facebook key app. On HelloJS, this is only a parameter that you can easily change.
I don't know if someone still stuck with this thing then please follow the method mentioned my #Alexy and then edit the 'lib/facebook-connect-plugin/index.js' file line from :
if(cordova.platformId === 'browser')
to
if(!window.cordova || (window.cordova && window.cordova.platformId === 'browser'))
Hope this Helps :)

Launch and endpoint inside servicemix

What do I have to do to call Endpoint.publish from a bundle in servicemix?
I have used wsdl2java to create an impl that I launch inside a BundleActivator:
LOG.info("WSBundle registering using endpoint...");
endpointAddress = substituteParameters(endpointAddress, ref);
Endpoint endpoint = Endpoint.publish(endpointAddress, service);
myEndpoints.put(service, endpoint);
LOG.info("WSBundle registered server at: "+endpointAddress);
This works fine inside the Eclipse IDE but fails when I run the bundle inside the service mix deploy area.
At first the failure was due to missing some classes in the following packages:
javax.xml.ws,
javax.xml.ws.spi,
org.apache.cxf.endpoint,
org.apache.cxf.frontend,
org.apache.cxf.jaxws,
org.apache.cxf.jaxws.spi,
After adding these to my manifest as imported packages I get the following error:
ERROR: Bundle WSExposer [187] EventDispatcher: Error during dispatch. (javax.xml.ws.spi.FactoryFinder$ConfigurationError: Provider org.apache.cxf.jaxws.spi.ProviderImpl not found)
javax.xml.ws.spi.FactoryFinder$ConfigurationError: Provider org.apache.cxf.jaxws.spi.ProviderImpl not found
at javax.xml.ws.spi.FactoryFinder$2.run(FactoryFinder.java:133)
at javax.xml.ws.spi.FactoryFinder.doPrivileged(FactoryFinder.java:238)
at javax.xml.ws.spi.FactoryFinder.newInstance(FactoryFinder.java:127)
at javax.xml.ws.spi.FactoryFinder.access$200(FactoryFinder.java:44)
at javax.xml.ws.spi.FactoryFinder$3.run(FactoryFinder.java:229)
at javax.xml.ws.spi.FactoryFinder.doPrivileged(FactoryFinder.java:238)
at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:163)
at javax.xml.ws.spi.Provider.provider(Provider.java:43)
at javax.xml.ws.Endpoint.publish(Endpoint.java:57)
My manifest file is as follows:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: WSBundle
Bundle-SymbolicName: WSBundle
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.company.soa.wsbundle.WSExposerActivator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: com.company.product.history.filtertypes.v1,
com.company.product.system.basetypes.v1,
com.company.svc.product.event.v1,
com.company.svc.product.service.event.v1,
com.company.svc.product.service.faults.v1,
javax.xml.ws,
javax.xml.ws.spi,
org.apache.cxf.endpoint,
org.apache.cxf.frontend,
org.apache.cxf.jaxws,
org.apache.cxf.jaxws.spi,
org.osgi.framework
Export-Package: com.company.soa.wsbundle
I found that you can switch service mix to use the Equinox frame work which resolved the issue.
in the etc/config.properties change the karaf.framework to eclipse:
karaf.framework=equinox

Resources