Backstage oAuth Github: Missing session cookie - node.js

Hope you're doing well! I'm looking for some kind of help. Will be really grateful for you if you provide me with some sort of a hint.
I'm setting up developer portal based on [Backstage.io][1] according to Getting started docs instructions.
I've added #backstage/plugin-auth-backend to the project root and configured it as described [here][2].
As soon as I try to load backstage web app I get the following error:
{"error":{"name":"AuthenticationError","message":"Refresh failed; caused by InputError: Missing session cookie"
And it's followed by the list of .ts files with errors including some scripts connected with node_modules/#backstage/plugin-auth-backend. Guys, really I don't know where I'm missing something.
Here are some key points in my app-config.yaml:
app:
title: Scaffolded Backstage App
baseUrl: http://0.0.0.0:3000
backend:
baseUrl: http://<publicIP>:7007
listen:
port: 7007
csp:
default-src: ["'self'", 'http:', 'https:']
connect-src: ["'self'", 'http:', 'https:']
script-src: ["'self", 'http:', 'https:','unsafe-inline', http://www.github.com", http://api.github.com"]
cors:
origin: http://*:3000
methods: [GET, POST, PUT, DELETE]
credentials: true
headers: X-Requested-With
auth:
environment: development
providers:
github:
development:
clientId: ${GITHUB_CLIENTID}
clientSecret: ${GITHUB_CLIENT_SECRET}
I have exported those env variables to current terminal and ran yarn dev
So when I try to login to Backstage using Github I get 401 Unathorized error response while trying to approach thar Request URL: http://<publicIP>:7007/api/auth/github/refresh?optional&env=development
[1]: https://backstage.io/
[2]: https://backstage.io/docs/auth/add-auth-provider

Related

ECONNREFUSED error using webpack-dev-server in Motoko project

I created a motoko backend and added some JavaScript and HTML for the frontend. Now I would like to deploy my project using webpack.
After the successfull deployment I get the following error interacting with the frontend:
[webpack-dev-server] [HPM] Error occurred while proxying request localhost:8080/api/v2/status to http://localhost:8000/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
Reading the documentation the frontend should run on the server http://localhost:8080 and API request will be proxyed to the replica on port 8000.
If I open port 8000 it says:
Could not find a canister id to forward to.
So from my understanding, the frontend server runs and if he makes an API call (e.g. calling a function within my code) it proxys it to port 8000, but the service on this port is inactive.
The webpack.config.js config for the proxy:
// proxy /api to port 8000 during development
devServer: {
proxy: {
"/api": {
target: "http://localhost:8000",
changeOrigin: true,
pathRewrite: {
"^/api": "/api",
},
},
},
hot: true,
watchFiles: [path.resolve(__dirname, "src", frontendDirectory)],
liveReload: true,
},
};
UPDATE
I fixed the issue. The API calls where routed to the wrong adress. I changed it in the webpack.config.js to http://127.0.0.1:8000/.
I fixed the issue. The API calls where routed to the wrong adress. I changed it in the webpack.config.js to http://127.0.0.1:8000/.

Content Security Policy issue when using auth0 with heroku

I'm trying to get auth0 to work with heroku, but having some difficulties.
I can get it to work locally without issues, but it just wouldn't work with Heroku
My setup:
React app which is being server from express as a static resource
Code for auth0 provider:
const providerConfig = {
domain: process.env.AUTH0_DOMAIN,
clientId: process.env.AUTH0_CLIENT_ID,
redirectUri: window.location.origin,
};
ReactDOM.render(
<Auth0Provider {...providerConfig}>
<BrowserRouter history={history}>
<App />
</BrowserRouter>
</Auth0Provider>,
document.getElementById("root")
);
The error I get when I try to login:
Refused to connect to 'https://small-dust-7659.eu.auth0.com/oauth/token' because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'connect-src' was not explicitly set, so 'default-src' is used as a fallback.
Any help is much appreciated, thanks!
Auth0 needs to know about your origin, so it can allow cross-origin (CORS) requests to be made from your site on Heroku.
There's a detailed description on how to set this up here.
Basically on your applications page you can set up your origins and URLs.
The issue was to do with helmet configuration..
I added the auth0 domain to connectSrc and it solved the issue
helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
objectSrc: ["'none'"],
scriptSrc: ["'self'", "unpkg.com", "polyfill.io"],
styleSrc: ["'self'", "https: 'unsafe-inline'"],
----> connectSrc: ["'self'", "xxxxxx.eu.auth0.com"],
upgradeInsecureRequests: [],
},
},
});

Deploying Nuxt JS SSR app to Google Cloud App Engine Standard

I am unable to deploy my Nuxt JS SSR app to Google Cloud App Engine.
The app is able to run locally both in dev and production mode.
The Nuxt JS documentation suggests using the app.yaml as follows:
runtime: nodejs10
instance_class: F2
handlers:
- url: /_nuxt
static_dir: .nuxt/dist/client
secure: always
- url: /(.*\.(gif|png|jpg|ico|txt))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg|ico|txt)$
secure: always
- url: /.*
script: auto
secure: always
env_variables:
HOST: '0.0.0.0'
However, the Google Cloud documentation suggests using nodejs14 as well as the env_variables for the bucket name which I assume is the same name as the staging bucket automatically created by Google App Engine.
runtime: nodejs14 # or another supported version
instance_class: F2
env_variables:
BUCKET_NAME: "staging.myapp.appspot.com"
handlers:
- url: /_nuxt
static_dir: .nuxt/dist/client
secure: always
- url: /(.*\.(gif|png|jpg|ico|txt))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg|ico|txt)$
secure: always
- url: /.*
script: auto
secure: always
When deploying with both of these app.yaml configurations it deploys successfully to Google App Engine however upon visiting the URL for the instance (myapp.uk.r.appspot.com) I am met with the error as follows:
Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.
And when visiting staging.myapp.appspot.com I am met with a range of errors from a generic Google 404 error to a certificate error. Does anyone have any idea about the correct app.yaml configuration for deploying a Nuxt JS SSR app to Google Cloud App Engine?
Does anyone have any idea about the correct app.yaml configuration for deploying a Nuxt JS SSR app to Google Cloud App Engine?
I replicated your case and deployed the basic tutorial deploying of Nuxt JS app in App Engine using your provided app.yaml configuration. Both configuration are working even I reduced the the instance_class from F2 to F1, its still working well.
As of now, the recommended version of nodejs is nodejs14 but the app is still working in App Engine Standard even the version is nodejs10. The env_variables is optional, you can define environment variables in your app.yaml file to make them available or use it inside your app.
Error:
Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.
The 500 error or server error is hard to find the cause. Look for the logs in Cloud Logging or click this link to direct go to console. Make sure that you are in GAE application > your service name > App Engine Version. Start looking for error appearing when accessing your application and look for error cause description. If you haven't find any try to switch to all logs.
Please note, it also requires the following API is already enabled:
App Engine API
Compute Engine API
Cloud Build API
Additional troubleshooting, double check the listening port on your application.
Please check the application logs to make sure whats happen on GAE
gcloud app logs tail
Then try my yaml file for nuxt SSR too:
runtime: nodejs14
service: nuxt
instance_class: F1
handlers:
- url: /_nuxt
static_dir: .nuxt/dist/client
secure: always
- url: /(.*\.(gif|png|jpg|ico|txt))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg|ico|txt)$
secure: always
- url: /.*
script: auto
secure: always
Solved the issue it seems to have been an oversight regarding specifying a different server port in nuxt.config.js of 8000 rather than the default.
By looking at the logs using:
gcloud app logs tail
This error became apparent:
✖ Nuxt Fatal Error
Error: listen EADDRNOTAVAIL: address not available *.*.*.*:8000
Try this configuration:
runtime: nodejs12
instance_class: F2
handlers:
- url: /_nuxt
static_dir: .nuxt/dist/client
secure: always
- url: /(.*\.(gif|png|jpg|ico|txt))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg|ico|txt)$
secure: always
- url: /.*
script: auto
secure: always
env_variables:
HOST: '0.0.0.0'
I have an nuxt app running in App Engine, and this is my Yaml config.
I suggest you to check if your application is Enabled in GCP/App Engine/Configurations=>Deactivate App field.

Override express-gateway config

I'm deploying an express gateway to Amazon ECS container, I'm trying to figure out what is the best way to override the serviceEndpoint part if the gateway.config.yml since service URLs are obviously different.
I need to change this
serviceEndpoints:
user:
url: 'http://localhost:3001'
auth:
url: 'http://localhost:3004'
customer:
url: 'http://localhost:3002'
to this:
serviceEndpoints:
user:
url: 'http://user.service:3001'
auth:
url: 'http://auth.service:3004'
customer:
url: 'http://customer.sevice:3002'
and so forth.
I asume I could maintain 2 copies of the config file and swap them in Docker build but I asume this is not the best alternative, implementing service discovery, I asume, would be another choice.
Any ideas?
TIA!
I found the solution, the config now uses ENVIRONMENT variables as:
serviceEndpoints:
user:
url: 'http://${USER_SERVICE:-localhost}:${USER_SERVICE_PORT:-3001}'
auth:
url: 'http://${AUTH_SERVICE:-localhost}:${AUTH_SERVICE_PORT:-3004}'
customer:
url: 'http://${CUSTIMER_SERVICE:-localhost}:${CUTOMER_SERVICE_PORT:-3002}'
and everything works.
Regards.

JHipster Social Login Google Authentication error Cannot POST /signin/google

Created an application from https://start.jhipster.tech/#/generate-application with JWT and Enabling Social Login, From Google generated the clientID, clientSecret and update the application.yml .
In google console's Client ID for Web application,
Authorized JavaScript origins
are specified as
http://localhost:8080
and
http://localhost:9000
The "Authorized redirect URIs" are set as http://localhost:8080/signin/google and http://localhost:9000/signin/google
After yarn install , yarn start and .mvnw ( spring-boot:run ), the application can be run at http://localhost:8080 and http://localhost:9000
Login with google works fine when application is accessed from http://localhost:8080 ,
when accessed from http://localhost:9000, the social login page says
Cannot POST /signin/google and url of the browser change to http://localhost:9000/signin/google
By default, the url for the spring social is not defined into the jhipster webpack configuration.
You should modify the file webpack/webpack.dev.js to add the /signin path to the dev server configuration as follows :
devServer: {
contentBase: './target/www',
proxy: [{
context: [
/* jhipster-needle-add-entity-to-webpack - JHipster will add entity api paths here */
'/api',
'/management',
'/swagger-resources',
'/v2/api-docs',
'/h2-console',
'/auth',
'/signin'
],
target: 'http://127.0.0.1:8080',
secure: false
}],
watchOptions: {
ignored: /node_modules/
}
}
And in the google api credentials, you should add in the redirect urls: http://localhost:9060/signin/google

Resources