Skip to content

Commit

Permalink
add auth0 provider and simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
wKich committed Oct 5, 2021
1 parent 00af962 commit bf7e82c
Show file tree
Hide file tree
Showing 14 changed files with 750 additions and 44 deletions.
1 change: 1 addition & 0 deletions examples/backstage/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
root: true,
extends: '../../',
};
2 changes: 2 additions & 0 deletions examples/backstage/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ site

# Sensitive credentials
*-credentials.yaml
./cypress/videos
./cypress/screenshots
7 changes: 6 additions & 1 deletion examples/backstage/app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ techdocs:

auth:
# see https://backstage.io/docs/auth/ to learn about auth providers
providers: {}
providers:
auth0:
development:
clientId: YOUR_AUTH0_CLIENT_ID
clientSecret: YOUR_AUTH0_CLIENT_SECRET
domain: localhost:4400

scaffolder:
github:
Expand Down
4 changes: 3 additions & 1 deletion examples/backstage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"node": "14 || 16"
},
"scripts": {
"dev": "concurrently \"yarn start\" \"yarn start-backend\"",
"dev": "concurrently \"yarn sim\" \"yarn start\" \"yarn start-backend\"",
"sim": "yarn workspace app sim",
"start": "yarn workspace app start",
"start-backend": "yarn workspace backend start",
"build": "lerna run build",
Expand All @@ -16,6 +17,7 @@
"clean": "backstage-cli clean && lerna run clean",
"diff": "lerna run diff --",
"test": "lerna run test --since origin/master -- --coverage",
"test:e2e": "concurrently \"yarn dev\" \"yarn workspace app cy:run\"",
"test:all": "lerna run test -- --coverage",
"lint": "lerna run lint --since origin/master --",
"lint:all": "lerna run lint --",
Expand Down
7 changes: 7 additions & 0 deletions examples/backstage/packages/app/cypress.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"audience": "https://thefrontside.auth0.com/api/v1/",
"domain": "localhost:4400",
"clientId": "YOUR_AUTH0_CLIENT_ID",
"connection": "Username-Password-Authentication",
"scope": "openid profile email offline_access"
}
6 changes: 4 additions & 2 deletions examples/backstage/packages/app/cypress.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"baseUrl": "http://localhost:3001",
"baseUrl": "http://localhost:3000",
"fixturesFolder": false,
"pluginsFile": false
"pluginsFile": false,
"chromeWebSecurity": false,
"defaultCommandTimeout": 20000
}
2 changes: 2 additions & 0 deletions examples/backstage/packages/app/cypress/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
videos
screenshots
6 changes: 0 additions & 6 deletions examples/backstage/packages/app/cypress/integration/app.js

This file was deleted.

17 changes: 17 additions & 0 deletions examples/backstage/packages/app/cypress/integration/auth0.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Button } from '@interactors/with-cypress';
import config from '../../cypress.env.json';

describe('log in', () => {
beforeEach(() => {
cy.logout();
});

it('should get token without signing in', () => {
cy.createSimulation(config)
.visit('/')
.given({ email: '[email protected]', password: 'passw0rd' })
.login()
.visit('/')
.contains('Log out');
});
});
1 change: 1 addition & 0 deletions examples/backstage/packages/app/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@simulacrum/auth0-cypress';
8 changes: 6 additions & 2 deletions examples/backstage/packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"react-use": "^15.3.3"
},
"devDependencies": {
"@interactors/with-cypress": "^0.1.2",
"@simulacrum/auth0-cypress": "../../integrations/cypress",
"@simulacrum/auth0-simulator": "../../packages/auth0",
"@testing-library/jest-dom": "^5.10.1",
"@testing-library/react": "^10.4.1",
"@testing-library/user-event": "^12.0.7",
Expand All @@ -45,13 +48,14 @@
"start-server-and-test": "^1.10.11"
},
"scripts": {
"sim": "export PORT=4000 && auth0-simulator",
"start": "backstage-cli app:serve",
"build": "backstage-cli app:build",
"test": "backstage-cli test",
"lint": "backstage-cli lint",
"clean": "backstage-cli clean",
"test:e2e": "cross-env PORT=3001 start-server-and-test start http://localhost:3001 cy:dev",
"test:e2e:ci": "cross-env PORT=3001 start-server-and-test start http://localhost:3001 cy:run",
"test:e2e": "start-server-and-test start http://localhost:3000 cy:dev",
"test:e2e:ci": "start-server-and-test start http://localhost:3000 cy:run",
"cy:dev": "cypress open",
"cy:run": "cypress run"
},
Expand Down
20 changes: 19 additions & 1 deletion examples/backstage/packages/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,29 @@ import { entityPage } from './components/catalog/EntityPage';
import { searchPage } from './components/search/SearchPage';
import { Root } from './components/Root';

import { AlertDisplay, OAuthRequestDialog } from '@backstage/core-components';
import {
AlertDisplay,
OAuthRequestDialog,
SignInPage,
SignInProviderConfig,
} from '@backstage/core-components';
import { createApp, FlatRoutes } from '@backstage/core-app-api';
import { auth0AuthApiRef } from '@backstage/core-plugin-api';

const githubProvider: SignInProviderConfig = {
id: 'auth0-auth-provider',
title: 'Auth0',
message: 'Sign in using Auth0',
apiRef: auth0AuthApiRef,
};

const app = createApp({
apis,
components: {
SignInPage: props => (
<SignInPage {...props} auto provider={githubProvider} />
),
},
bindRoutes({ bind }) {
bind(catalogPlugin.externalRoutes, {
createComponent: scaffolderPlugin.routes.root,
Expand Down
Loading

0 comments on commit bf7e82c

Please sign in to comment.