Is aws-amplify with auth broken? - javascript

I am trying to build a react app which will use the aws hosted ui for authentication. I am trying to use aws-amplify to achieve this, and so far I am having no such luck.
Here the docs state that the auth config should look like this.
const oauth = {
domain : 'your-domain-prefix.auth.us-east-1.amazoncognito.com',
scope : ['phone', 'email', 'profile', 'openid','aws.cognito.signin.user.admin'],
redirectSignIn : 'http://www.example.com/signin/',
redirectSignOut : 'http://www.example.com/signout/',
responseType: 'code',
}
But when I use this config setup I get the following error.
The parameters: App client Id, App web domain, the redirect URL when
you are signed in and the redirect URL when you are signed out are
required.
As you can see, those params are clearly supplied. So I clicked on the source map file linked in my console with the error message, and saw this.
if (data == null || !ClientId || !AppWebDomain || !RedirectUriSignIn || !RedirectUriSignOut) {
throw new Error(this.getCognitoConstants().PARAMETERERROR);
}
Which makes it seem more like the config should look a little something like this.
const auth = {
AppWebDomain: "aaaaa",
TokenScopesArray: ["phone", "email", "profile", "openid", "aws.cognito.signin.user.admin"],
RedirectUriSignIn: "http://localhost:3000",
RedirectUriSignOut: "http://localhost:3000",
responseType: "token",
ClientId: "aaa",
UserPoolId: "aaa",
};
But when doing this, and trying to send the user to the hosted ui as the docs say here I get this error.
Uncaught TypeError: Cannot read property 'domain' of undefined
Once again I looked at the source and found this.
var domain = config.domain,
Which makes it seem like its expecting the config which does not work.
At this point I am really lost and can use any help at all.

Going through the Auth.ts code, it appears that you have to include the userPoolId and userPoolWebClientId fields, in addition to oauth. Here's how I got it to work:
const oauth = {
domain: 'XXXXXX.auth.us-west-2.amazoncognito.com',
scope: ['phone', 'email', 'profile', 'openid', 'aws.cognito.signin.user.admin'],
redirectSignIn: 'http://localhost:3000/',
redirectSignOut: 'http://localhost:3000/',
responseType: 'code'
};
Auth.configure({
oauth: oauth,
region: 'us-west-2',
userPoolId: 'us-west-2_XXXXXXXXX',
userPoolWebClientId: 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
});

Related

Receiving 401 Unauthorized error in Sendgrid with Strapi

I'm trying to add a "forgot password" link in my application, using the built-in API provided by Strapi. I've included the configuration for Sendgrid in config/plugins.js:
module.exports = ({ env }) => ({
email: {
provider: "sendgrid",
providerOptions: {
apiKey: env('SENDGRID_API_KEY'),
},
settings: {
defaultFrom: "myemail#gmail.com",
defaultReplyTo: "myemail#gmail.com",
},
},
});
Every answer I find about this error is about adding the API key in the environment variables, which I've already done (and re-done) several times. I also re-created my API key twice, in case it expired, but it's still the same. I don't understand, it was working perfectly well a couple days ago but now I'm stuck on this error. Any idea what could be the issue here?
Probably indeed the expression env('SENDGRID_API_KEY') is not resolving the correct api key. You can also directly put your api key in the json like this:
module.exports = ({ env }) => ({
email: {
provider: "sendgrid",
providerOptions: {
apiKey: 'SG.MY_SENDGRID_API_KEY',// <== not using the env function
},
settings: {
defaultFrom: "myemail#gmail.com",
defaultReplyTo: "myemail#gmail.com",
},
},
If this works, the plugin is working, and you can focus on why the env() function is not resolving the variable

Error with Gatsby when trying to proxy request

I am getting an error when trying to proxy my dev url through Gatsby. In my gatsby-config.js I have:
proxy: [
{
prefix: '/myaccount',
url: 'https://www-dev.site.com',
},
],
Gatsby Proxy Error Screenshot
Error when trying to proxy request "/myaccount/" to "https://www-dev.site.com/myaccount/" write EPROTO 4584046080:error:14094458:SSL routines:ssl3_read_bytes:tlsv1 unrecognized name:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1544:SSL alert number 112
RequestError: write EPROTO 4555591168:error:14094458:SSL routines:ssl3_read_bytes:tlsv1 unrecognized name:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1544:SSL alert number 112
This was working and all of a sudden stopped.
As it has been said, it looks like a certificate issue (because of the SSL). Without more implementation details it's difficult to guess if a proposed solution will work on your scenario but you can try setting the security as false (secure: false) to don't reject self-signed certificates. In your gatsby-config.js:
const { createProxyMiddleware } = require("http-proxy-middleware")
module.exports = {
developMiddleware: app => {
app.use(
"/.netlify/functions/",
createProxyMiddleware({
target: "http://localhost:9000",
secure: false,
pathRewrite: {
"/.netlify/functions/": "",
},
})
)
},
Docs: https://www.gatsbyjs.com/docs/api-proxy/#self-signed-certificates
Tweak it to adapt it to your needs, replacing /.netlify/functions/ for your API endpoint.

How to get Azure AD authentication to work in production with msal-browser in my Next.js application?

The following implementation of msal works without issues when I run it on localhost. But when I deploy it to an Azure App Service the clientId and/or tenantID seems to become undefined, even when I tried experimenting with placing the id strings directly into the file. Here is the error I get when i try to click the login button in production:
GET https://login.microsoftonline.com/undefined/v2.0/.well-known/openid-configuration 400 (Bad Request)
Uncaught (in promise) ClientAuthError: endpoints_resolution_error: Error: could not resolve endpoints. Please check network and try again. Detail: ClientAuthError: openid_config_error: Could not retrieve endpoints. Check your authority and verify the .well-known/openid-configuration endpoint returns the required endpoints. Attempted to retrieve endpoints from: https://login.microsoftonline.com/undefined/v2.0/.well-known/openid-configuration
at t [as constructor] (_app-3866deb516d5bf6f9628.js:1)
at new t (_app-3866deb516d5bf6f9628.js:1)
at Function.t.createEndpointDiscoveryIncompleteError (_app-3866deb516d5bf6f9628.js:1)
at Function.<anonymous> (_app-3866deb516d5bf6f9628.js:1)
at _app-3866deb516d5bf6f9628.js:1
at Object.throw (_app-3866deb516d5bf6f9628.js:1)
at s (_app-3866deb516d5bf6f9628.js:1)
And here is the msal implementation:
import * as msal from "#azure/msal-browser";
function redirUri() {
if (process.env.NODE_ENV == "development") {
return "/"
} else {
return "https://somewebsitename.azurewebsites.net/"
}
}
const msalConfig = {
auth: {
clientId: process.env.NEXT_PUBLIC_AZURE_AD_CLIENT_ID,
authority: `https://login.microsoftonline.com/${process.env.NEXT_PUBLIC_AZURE_AD_TENANT_ID}`,
redirectUri: redirUri()
}
};
const msalInstance = new msal.PublicClientApplication(msalConfig);
export { msalInstance }
What is the correct way to do this?
You can't get the app setting in Azure app service configuration.
You can get the ClientID and tenant Id from your application configuration by doing this.
process.env.clientId and process.env.tenantId
Ensure you have configured the following settings on the portal:

Setting AWS SDK credentials in Node

I am having trouble setting the aws credentials for a react app that needs the aws sdk. I have set up my credentials file in the '~/.aws/credentials' path, and I know this is okay. However, I don't know how to go about this in my jsx file. My understanding was that the SDK checks this credentials file on its own.
Here is my code:
process.env.AWS_SDK_LOAD_CONFIG = true;
var AWS = require("aws-sdk");
console.log(AWS.config)
But when I log the AWS.config object, I see credentials: null, region: null
Image of console log
I'd really appreciate any help!
Are you sure everything is fine with your .aws/config and .aws/credentials files?
I've run your code and I got below result. Please note I don't have the config file so region is undefined.
Config {
credentials:
SharedIniFileCredentials {
expired: false,
expireTime: null,
accessKeyId: 'xxx',
sessionToken: undefined,
filename: '/home/juzeff/.aws/credentials',
profile: 'default',
disableAssumeRole: true },
credentialProvider:
CredentialProviderChain {
providers: [ [Function], [Function], [Function], [Function] ] },
region: undefined,
If you load the credentials with AWS_SDK_LOAD_CONFIG make sure you have the [default] profile specified in your credentials file. If you have multiple profiles load the one you want to use this way:
const profile = 'corporate-bucket';
const credentials = new AWS.SharedIniFileCredentials({ profile });
AWS.config.credentials = credentials;
assuming your .aws/credentials file looks like this:
[corporate-bucket]
aws_access_key_id = xxx
aws_secret_access_key = yyy

auth0 cannot read poperty options of undefined

I try to get auth0 running on a simple react app.
I create a auth0 object with the folling parameter:
this.auth0 = new auth0.WebAuth({
domain: AUTH_CONFIG.domain,
clientID: AUTH_CONFIG.clientId,
redirectUri: AUTH_CONFIG.redirectUri,
audience: `https://${AUTH_CONFIG.domain}/userinfo`,
responseType: AUTH_CONFIG.responseType,
scope: AUTH_CONFIG.scope,
});
after I logg in on the Auth0 website and get redirected to my callback url I get the error
cannot read poperty of undefined
I just cant figer out where this error located.
In my Applcation in auth0 i configured: Allowed Callback URLs: http://localhost:3000/callback

Categories