2 |
--------------------------------------------------------------------------------
/typings.json:
--------------------------------------------------------------------------------
1 | {
2 | "globalDependencies": {
3 | "core-js": "registry:dt/core-js#0.0.0+20160602141332"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | myalcoholist-web.iml
2 | .idea
3 | config/*
4 | !config/*.defaults
5 | node_modules
6 | dist
7 | typings
8 | client/**/*.js
9 | client/**/*.js.map
10 | WebServer
11 | webpack-log
12 | cert/*
13 |
--------------------------------------------------------------------------------
/client/ts/app/help.component.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by ufk on 23/06/2016.
3 | */
4 |
5 | import { Component } from "@angular/core";
6 |
7 |
8 | @Component({
9 | selector: "help",
10 | templateUrl: "/www/help.html"
11 | })
12 | export class HelpComponent {
13 | }
--------------------------------------------------------------------------------
/client/ts/app/main.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by ufk on 08/10/2016.
3 | */
4 |
5 | import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
6 | import { AppModule } from "./app.module";
7 |
8 | const platform = platformBrowserDynamic();
9 | platform.bootstrapModule(AppModule);
--------------------------------------------------------------------------------
/client/ts/app/welcome.component.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by ufk on 23/06/2016.
3 | */
4 |
5 | import { Component } from "@angular/core";
6 |
7 |
8 | @Component({
9 | selector: "welcome",
10 | templateUrl: "/www/welcome.html"
11 | })
12 | export class WelcomeComponent {
13 | }
--------------------------------------------------------------------------------
/glpm.json:
--------------------------------------------------------------------------------
1 | {
2 | "packages": [
3 | "github.com/go-ini/ini",
4 | "github.com/gorilla/mux",
5 | "github.com/jingweno/negroni-gorelic",
6 | "github.com/phyber/negroni-gzip/gzip",
7 | "github.com/unrolled/secure",
8 | "github.com/urfave/negroni"
9 | ]
10 | }
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "module": "commonjs",
5 | "moduleResolution": "node",
6 | "sourceMap": true,
7 | "emitDecoratorMetadata": true,
8 | "experimentalDecorators": true,
9 | "removeComments": false,
10 | "noImplicitAny": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/client/www/styles.css:
--------------------------------------------------------------------------------
1 | h1 {
2 | color: #369;
3 | font-family: Arial, Helvetica, sans-serif;
4 | font-size: 250%;
5 | }
6 | body {
7 | margin: 2em;
8 | }
9 |
10 | /*
11 | * See https://github.com/angular/angular.io/blob/master/public/docs/_examples/styles.css
12 | * for the full set of master styles used by the documentation samples
13 | */
14 |
--------------------------------------------------------------------------------
/config/app.config.js.defaults:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by ufk on 29/06/2016.
3 | */
4 |
5 | module.exports = {
6 | webServer: {
7 | appBaseHref : JSON.stringify("/")
8 | },
9 | auth0: {
10 | apiKey: JSON.stringify("API_KEY"),
11 | domain: JSON.stringify("DOMAIN.auth0.com"),
12 | callbackUrl: JSON.stringify("CALLBACK_URL")
13 | }
14 | };
15 |
--------------------------------------------------------------------------------
/client/ts/app/app.component.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by ufk on 23/06/2016.
3 | */
4 |
5 | import { Component } from "@angular/core";
6 | import {Auth} from "./auth.service";
7 |
8 |
9 | @Component({
10 | selector: "my-app",
11 | providers: [Auth],
12 | templateUrl: "/www/my-app.html"
13 | })
14 | export class AppComponent {
15 | constructor(private auth: Auth) {
16 |
17 | }
18 | }
--------------------------------------------------------------------------------
/config/config.ini.defaults:
--------------------------------------------------------------------------------
1 | [Server]
2 | IsProduction=false
3 | ServerHost=
4 |
5 | [SslCert]
6 | CertificateFile=cert/.crt
7 | PrivateKeyFile=cert/.key
8 | OtherCertificates[]=,[....]
9 |
10 | [Auth0]
11 | AccountDomain=
12 |
13 | [NewRelic]
14 | Licensekey=
15 | AppName=
16 |
17 | [WebServer]
18 | HttpsPort=10444
19 | ReadTimeout=5
20 | WriteTimeout=10
21 |
--------------------------------------------------------------------------------
/client/www/my-app.html:
--------------------------------------------------------------------------------
1 |
2 | Welcome
3 | Help
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/client/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Demo App
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/cert/CertLoader.go:
--------------------------------------------------------------------------------
1 | package cert
2 |
3 | import (
4 | "crypto/tls"
5 | "log"
6 | "crypto/x509"
7 | "io/ioutil"
8 | "../config"
9 | )
10 |
11 | var TlsConfig *tls.Config;
12 |
13 | func init() {
14 | cert, err := tls.LoadX509KeyPair(config.CfgIni.CertificateFile,config.CfgIni.PrivateKeyFile)
15 | if err != nil {
16 | log.Fatalf("server: loadkeys: %s", err)
17 |
18 | }
19 | certpool := x509.NewCertPool()
20 | for _, crFile := range config.CfgIni.OtherCertificates {
21 | pem, err := ioutil.ReadFile(crFile)
22 | if err != nil {
23 | log.Fatalf("Failed to read client certificate authority: %v", err)
24 | }
25 | if !certpool.AppendCertsFromPEM(pem) {
26 | log.Fatalf("Can't parse client certificate authority")
27 | }
28 | }
29 |
30 | TlsConfig = &tls.Config{
31 | Certificates: []tls.Certificate{cert},
32 | ClientCAs: certpool,
33 | }
34 | TlsConfig.BuildNameToCertificate()
35 | }
36 |
--------------------------------------------------------------------------------
/client/ts/app/auth.service.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by ufk on 24/06/2016.
3 | */
4 |
5 | import {Injectable} from "@angular/core";
6 | import {tokenNotExpired} from "angular2-jwt";
7 |
8 |
9 | // Avoid name not found warnings
10 | declare var APP_CONFIG: any;
11 | declare var Auth0Lock: any;
12 |
13 | @Injectable()
14 | export class Auth {
15 | // Configure Auth0
16 | lock = new Auth0Lock(APP_CONFIG.auth0.apiKey, APP_CONFIG.auth0.domain, {});
17 |
18 | constructor() {
19 | // Add callback for lock `authenticated` event
20 | this.lock.on("authenticated", (authResult) => {
21 | localStorage.setItem("id_token", authResult.idToken);
22 | });
23 | }
24 |
25 | public login() {
26 | this.lock.show({
27 | callbackURL: APP_CONFIG.auth0.callbackUrl
28 | });
29 | };
30 |
31 | public authenticated() {
32 | // Check if there"s an unexpired JWT
33 | // It searches for an item in localStorage with key == "id_token"
34 | return tokenNotExpired();
35 | };
36 |
37 | public logout() {
38 | // Remove token from localStorage
39 | localStorage.removeItem("id_token");
40 | };
41 | }
--------------------------------------------------------------------------------
/client/ts/app/app.module.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by ufk on 08/10/2016.
3 | */
4 |
5 | import { NgModule } from "@angular/core";
6 | import { BrowserModule } from "@angular/platform-browser";
7 | import { RouterModule } from "@angular/router";
8 | import {AppComponent} from "./app.component";
9 | import {WelcomeComponent} from "./welcome.component";
10 | import {HelpComponent} from "./help.component";
11 | import {APP_BASE_HREF} from "@angular/common";
12 | import { MaterialModule } from "@angular/material";
13 | import { AUTH_PROVIDERS } from "angular2-jwt";
14 |
15 | declare var APP_CONFIG:any;
16 |
17 | @NgModule({
18 | providers: [AUTH_PROVIDERS,{provide: APP_BASE_HREF, useValue: APP_CONFIG.webServer.appBaseHref}],
19 | imports: [ MaterialModule.forRoot(),BrowserModule,RouterModule.forRoot([
20 | { path: "",redirectTo:"welcome",pathMatch:"full"},
21 | { path: "welcome", component: WelcomeComponent },
22 | { path: "help",component: HelpComponent},
23 | { path: "**",redirectTo:"welcome"}
24 | ]) ],
25 | declarations: [
26 | AppComponent,HelpComponent,WelcomeComponent
27 | ],
28 | bootstrap: [AppComponent]
29 | })
30 | export class AppModule { }
--------------------------------------------------------------------------------
/src/config/Config.go:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | import (
4 | "log"
5 | "github.com/go-ini/ini"
6 | )
7 |
8 | const (
9 | configIniPath string = "config/config.ini"
10 | )
11 |
12 | type SslCert struct {
13 | CertificateFile string
14 | PrivateKeyFile string
15 | OtherCertificates []string
16 | }
17 |
18 | type Server struct {
19 | IsProduction bool
20 | ServerName string
21 | }
22 |
23 | type Auth0 struct {
24 | AccountDomain string
25 | }
26 |
27 | type NewRelic struct {
28 | Licensekey string
29 | AppName string
30 | }
31 |
32 | type WebServer struct {
33 | HttpsPort uint64
34 | ReadTimeout uint
35 | WriteTimeout uint
36 | }
37 |
38 | type ConfigIni struct {
39 | SslCert
40 | Server
41 | NewRelic
42 | Auth0
43 | WebServer
44 | }
45 |
46 | var CfgIni *ConfigIni
47 |
48 | func parseIni(configIniPath string) (*ConfigIni) {
49 | cfg, err := ini.Load(configIniPath);
50 | if (err != nil) {
51 | log.Fatalf("error loading config.ini: %v", err);
52 | }
53 | cfgIni := new(ConfigIni);
54 | err = cfg.MapTo(cfgIni);
55 | if (err != nil) {
56 | log.Fatalf("error parsing config.ini: %v", err);
57 | }
58 | return cfgIni
59 | }
60 |
61 | func init() {
62 | CfgIni = parseIni(configIniPath);
63 | }
64 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "go-angular2-material-auth0-and-more",
3 | "version": "1.0.1",
4 | "scripts": {
5 | "build": "webpack",
6 | "start": "webpack-dev-server",
7 | "postinstall": "typings install",
8 | "typings": "typings"
9 | },
10 | "license": "ISC",
11 | "dependencies": {
12 | "@angular/common": "^2.1.0-rc.0",
13 | "@angular/compiler": "^2.1.0-rc.0",
14 | "@angular/core": "^2.1.0-rc.0",
15 | "@angular/forms": "^2.1.0-rc.0",
16 | "@angular/http": "^2.1.0-rc.0",
17 | "@angular/material": "^2.0.0-alpha.9-experimental-pizza",
18 | "@angular/platform-browser": "^2.1.0-rc.0",
19 | "@angular/platform-browser-dynamic": "^2.1.0-rc.0",
20 | "@angular/router": "^3.0.2",
21 | "@angular/upgrade": "^2.1.0-rc.0",
22 | "angular2-in-memory-web-api": "0.0.21",
23 | "angular2-jwt": "^0.1.23",
24 | "auth0-lock": "^10.4.0",
25 | "core-js": "^2.4.1",
26 | "glob": "^7.1.1",
27 | "reflect-metadata": "^0.1.8",
28 | "rxjs": "^5.0.0-beta.12",
29 | "tslint": "^3.15.1",
30 | "typings": "^1.4.0",
31 | "zone.js": "^0.6.25"
32 | },
33 | "devDependencies": {
34 | "awesome-typescript-loader": "^2.2.4",
35 | "babel-core": "^6.16.0",
36 | "babel-loader": "^6.2.5",
37 | "babel-preset-es2015": "^6.16.0",
38 | "brfs": "^1.4.3",
39 | "codelyzer": "1.0.0-beta.0",
40 | "extended-define-webpack-plugin": "^0.1.2",
41 | "glob": "^7.1.0",
42 | "json-loader": "^0.5.4",
43 | "packageify": "^1.0.0",
44 | "transform-loader": "^0.2.3",
45 | "ts-loader": "^0.8.2",
46 | "tslint": "^3.15.1",
47 | "tslint-loader": "^2.1.5",
48 | "typescript": "^2.0.3",
49 | "typings": "^1.4.0",
50 | "webpack": "^2.1.0-beta.25",
51 | "webpack-dev-server": "^1.16.2"
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "directive-selector-name": [true, "camelCase"],
7 | "component-selector-name": [true, "kebab-case"],
8 | "directive-selector-type": [true, "attribute"],
9 | "component-selector-type": [true, "element"],
10 | "directive-selector-prefix": [true, "sg"],
11 | "component-selector-prefix": [true, "sg"],
12 | "use-input-property-decorator": true,
13 | "use-output-property-decorator": true,
14 | "use-host-property-decorator": true,
15 | "no-attribute-parameter-decorator": true,
16 | "no-input-rename": true,
17 | "no-output-rename": true,
18 | "no-forward-ref" :true,
19 | "use-life-cycle-interface": true,
20 | "use-pipe-transform-interface": true,
21 | "pipe-naming": [true, "camelCase", "sg"],
22 | "component-class-suffix": true,
23 | "directive-class-suffix": true,
24 | "import-destructuring-spacing": true,
25 | "class-name": true,
26 | "comment-format": [
27 | true,
28 | "check-space"
29 | ],
30 | "indent": [
31 | true,
32 | "spaces"
33 | ],
34 | "no-duplicate-variable": true,
35 | "no-eval": true,
36 | "no-internal-module": true,
37 | "no-trailing-whitespace": true,
38 | "no-var-keyword": true,
39 | "one-line": [
40 | true,
41 | "check-open-brace",
42 | "check-whitespace"
43 | ],
44 | "quotemark": [
45 | true,
46 | "double"
47 | ],
48 | "semicolon": [
49 | true,
50 | "always"
51 | ],
52 | "triple-equals": [
53 | true,
54 | "allow-null-check"
55 | ],
56 | "typedef-whitespace": [
57 | true,
58 | {
59 | "call-signature": "nospace",
60 | "index-signature": "nospace",
61 | "parameter": "nospace",
62 | "property-declaration": "nospace",
63 | "variable-declaration": "nospace"
64 | }
65 | ],
66 | "variable-name": [
67 | true,
68 | "ban-keywords"
69 | ],
70 | "whitespace": [
71 | true,
72 | "check-branch",
73 | "check-decl",
74 | "check-operator",
75 | "check-separator",
76 | "check-type"
77 | ]
78 | }
79 | }
--------------------------------------------------------------------------------
/src/main/WebServer.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "strconv"
6 | "../config"
7 | "net/http"
8 | "github.com/urfave/negroni"
9 | "github.com/phyber/negroni-gzip/gzip"
10 | "github.com/unrolled/secure"
11 | "time"
12 | "github.com/gorilla/mux"
13 | "github.com/jingweno/negroni-gorelic"
14 | "../cert"
15 | )
16 |
17 | var secureMiddleware *secure.Secure = secure.New(secure.Options{
18 | IsDevelopment: !config.CfgIni.IsProduction,
19 | SSLRedirect: true,
20 | SSLHost: config.CfgIni.ServerName,
21 | SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"},
22 | STSSeconds: 315360000,
23 | STSIncludeSubdomains: true,
24 | STSPreload: true,
25 | FrameDeny: true,
26 | ContentTypeNosniff: true,
27 | BrowserXssFilter: true,
28 | ContentSecurityPolicy: "default-src 'self'; img-src 'self' cdn.auth0.com; connect-src 'self' " + config.CfgIni.AccountDomain + ";style-src 'self' 'unsafe-inline' fonts.googleapis.com; font-src 'self' fonts.gstatic.com;script-src 'self' 'unsafe-eval' cdn.auth0.com;",
29 | PublicKey: `pin-sha256="base64+primary=="; pin-sha256="base64+backup=="; max-age=5184000; includeSubdomains; report-uri="https://www.example.com/hpkp-report"`,
30 | })
31 |
32 | func notFound(w http.ResponseWriter, r *http.Request) {
33 | http.ServeFile(w, r, "client/www/index.html")
34 | }
35 |
36 | func main() {
37 | log.Print("started web server...");
38 | httpsPortStr := ":" + strconv.FormatUint(config.CfgIni.HttpsPort, 10)
39 | log.Printf("starting https web server at port %v", config.CfgIni.HttpsPort)
40 | r := mux.NewRouter()
41 | r.PathPrefix("/node_modules/").Handler(http.StripPrefix("/node_modules", http.FileServer(http.Dir(("node_modules")))))
42 | r.PathPrefix("/dist/").Handler(http.StripPrefix("/dist", http.FileServer(http.Dir(("dist")))))
43 | r.PathPrefix("/ts/").Handler(http.StripPrefix("/ts", http.FileServer(http.Dir(("client/ts")))))
44 | r.PathPrefix("/www/").Handler(http.StripPrefix("/www",http.FileServer(http.Dir("client/www"))))
45 | r.PathPrefix("/").HandlerFunc(notFound)
46 | n := negroni.New()
47 | n.Use(gzip.Gzip(gzip.DefaultCompression))
48 | n.UseHandler(r)
49 | n.Use(negroni.HandlerFunc(secureMiddleware.HandlerFuncWithNext))
50 | if config.CfgIni.IsProduction {
51 | n.Use(negronigorelic.New(config.CfgIni.Licensekey, config.CfgIni.AppName, true))
52 | }
53 | n.Use(negroni.NewLogger())
54 | n.Use(negroni.NewRecovery())
55 | srv := &http.Server{
56 | Addr: httpsPortStr,
57 | Handler: n,
58 | ReadTimeout: time.Duration(config.CfgIni.ReadTimeout) * time.Second,
59 | WriteTimeout: time.Duration(config.CfgIni.WriteTimeout) * time.Second,
60 | TLSConfig: cert.TlsConfig,
61 | }
62 | err := srv.ListenAndServeTLS(config.CfgIni.CertificateFile,config.CfgIni.PrivateKeyFile)
63 | if err != nil {
64 | log.Fatalf("https server stopped with the following error: %v", err)
65 | } else {
66 | log.Print("https server stopped with no error")
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | var appConfig = require("./config/app.config");
2 | var webpack = require("webpack");
3 | const DefinePlugin = require("webpack/lib/DefinePlugin");
4 | const LoaderOptionsPlugin = require("webpack/lib/LoaderOptionsPlugin");
5 |
6 | module.exports = {
7 | plugins: [
8 | new DefinePlugin({
9 | APP_CONFIG: appConfig
10 | }),
11 | new LoaderOptionsPlugin({
12 | options: {
13 | tslint: {
14 | configuration: {
15 | rules: {
16 | quotemark: [true, "double"]
17 | }
18 | },
19 |
20 | // tslint errors are displayed by default as warnings
21 | // set emitErrors to true to display them as errors
22 | emitErrors: false,
23 |
24 | // tslint does not interrupt the compilation by default
25 | // if you want any file with tslint errors to fail
26 | // set failOnHint to true
27 | failOnHint: true,
28 |
29 | // name of your formatter (optional)
30 | formatter: "",
31 |
32 | // path to directory containing formatter (optional)
33 | formattersDirectory: "node_modules/tslint-loader/formatters/",
34 |
35 | // These options are useful if you want to save output to files
36 | // for your continuous integration server
37 | fileOutput: {
38 | // The directory where each file"s report is saved
39 | dir: "./webpack-log/",
40 |
41 | // The extension to use for each report"s filename. Defaults to "txt"
42 | ext: "xml",
43 |
44 | // If true, all files are removed from the report directory at the beginning of run
45 | clean: true,
46 |
47 | // A string to include at the top of every report file.
48 | // Useful for some report formats.
49 | header: "\n",
50 |
51 | // A string to include at the bottom of every report file.
52 | // Useful for some report formats.
53 | footer: ""
54 | }
55 | }
56 | }
57 | })
58 |
59 | ],
60 | devtool: 'source-map',
61 | entry: {
62 | "app": ["./client/ts/app/main.ts"]
63 | },
64 | output: {
65 | path: __dirname,
66 | filename: "./dist/bundle.js"
67 | },
68 | resolve: {
69 | extensions: [".js", ".ts"],
70 | },
71 | module: {
72 | loaders: [
73 | {
74 | test: /\.json$/,
75 | loader: "json-loader"
76 | },
77 | {
78 | test: /\.ts$/,
79 | loader: 'awesome-typescript-loader'
80 | },
81 | {
82 | test: /\.ts$/,
83 | loader: 'tslint',
84 | exclude: /(node_modules)/,
85 | enforce: 'pre'
86 | },
87 | ],
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DEPRECATED
2 |
3 | after some wonderful users comments,
4 | this project is deprecated in favor of https://github.com/tuxin-skeleton
5 |
6 | # go-angular2-material-auth0-and-more
7 |
8 | this is a starter kit i was missing when I first started to learn go.
9 | which wasn't that long ago :) so if you have any suggestions to improve it,
10 | please let me know.
11 |
12 | included go features:
13 |
14 | - https web server
15 | - go-ini - ini parser
16 | - negroni with the negroni-gorelic package
17 | - mux
18 |
19 | included javascript features:
20 |
21 | * angular2 2.1.0-rc.0
22 | * angular2 router 3.0.2
23 | * angular2 material 2.0.0-alpha.9-experimental-pizza
24 | * typescript 2.0.3
25 | * webpack 2.1.0-beta.25
26 | * auth0 - auth0lock 10.4.0
27 | * tslint
28 | * codelyzer
29 | * Google Material Icons
30 |
31 | ## how to build
32 |
33 | ### building go related packages
34 |
35 | welp, first you need to have Go Installed :) then you need to use go to download the following go modules:
36 |
37 | - github.com/go-ini/ini
38 | - github.com/urfave/negroni
39 | - github.com/phyber/negroni-gzip/gzip
40 | - github.com/jingweno/negroni-gorelic
41 | - github.com/unrolled/secure
42 | - github.com/gorilla/mux
43 |
44 |
45 | ### 3 ways to install packages:
46 |
47 | 1. just execute `go get ` on each package in the list.
48 | 2. execute `go get ./...` on the root of the project
49 | 3. I included glpm.json file (https://github.com/kfirufk/glpm), so if you want to use this package manager,
50 | install it with `go get -u github.com/kfirufk/glpm`, and then type `glpm -install` in the root directory of your project.
51 |
52 | ### building client (javascript) related packages
53 |
54 | first you need to have the following nodejs global packages installed:
55 |
56 | - typescript
57 | - typings
58 | - webpack
59 |
60 | if you don't, please download and install nodejs, after that execute `npm install -g `. that will install the packges globally.
61 |
62 | now all you need is to execute `npm install` in the project's root directory to install the required packages.
63 |
64 | ### webpack
65 | since we are using webpack, we need to use the globally installed webpack package to build our client source files.
66 | simply execute `npm run build` in the project's root directory.
67 |
68 | ### configuration
69 |
70 | ###- config.ini
71 |
72 | please copy `config/config.ini.defaults` to `config/config.ini`, open it with your favorite text editor, and change it according to your configuration.
73 |
74 | in general you have 3 categories in config.ini
75 |
76 | - `Server` - which includes the host name of the server and a flag that indicates if it's in a production environment or not.
77 | - `SslCert` - which contains the pem and key files locations to property start an HTTPS Server.
78 | - `NewRelic` - which includes the license key of your newrelic account and the application name that will appear on the dashboard
79 | - `WebServer` - which includes the https port to open, and finally the readn write timeouts for https requests.
80 | - `Auth0` - account domain (to configure secure package to allow login requests)
81 | ###- app.config.js
82 |
83 | please copy `config/app.config.js.defaults` to `config/app.config.js`, open it with your favorite text editor, and change it according to your configuration.
84 |
85 | for now there is only one category to modify
86 |
87 | - `auth0` - which includes the api key and domain name of your auth0 account.
88 | - `webServer` - which includes the APP_BASE_HREF value to be set.
89 |
90 | ### compile the go project
91 |
92 | execute from the project's root directory the following command: `go build src/main/WebServer.go`
93 |
94 | # Things to notice
95 |
96 | ##- Go Package github.com/unrolled/secure
97 |
98 | I've installed and configured for you this awesome security package for your web server.
99 | you should check and understand the ContentSecurityPolicy of the secureMiddleware variable in the main go file (at src/main/WebServer.go).
100 | I configured the content security policies to allow all the wonderful features that this project has, but if you don't quite understand this subject,
101 | I would strongly recommend to checkout `http://content-security-policy.com/` in order for you to quickly resolve future security issue
102 | that are detected by your own code or 3rd party libraries.
103 |
104 | ##- Angular Routes Configuration
105 |
106 | ### auth0
107 | after a succesfull login, the redirection for some reason works but provides errors in the javascript console about not finding a valid route.
108 | in order to work-around this problem, I created a wildcard route so every invalid route will be routed back to the
109 | welcome component. the routes are configured at `client/ts/app/routers.ts`.
110 |
111 | ##- SSL Certificates
112 |
113 | I use GoDaddy SSL Certificate, that comes with a primary crt file, the server key file, and the bundle file sf_bundle-g2-g1.
114 |
115 | the docs says the following: `If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.`
116 |
117 | so in my case all i needed to do is to append the bundle file to the main crt file.
118 |
119 | I checked the grade of the SSL Certificate using `https://www.ssllabs.com/ssltest/` and I got grade A.
120 |
121 | I did leave the directive `OtherCertificates` under the SslCert category of config.ini, just in case for some reason it needed to be loaded separately.
122 |
123 | # Tested
124 |
125 | this package was tested on a macbook pro with macOS Sierra, using nodejs 6.7.0 (installed with nvm) and go 1.7.1 installed with homebrew.
126 |
127 | if for some reason you encounter problems with different versions of node or go, please let me know.
128 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------