Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #81

Open
wants to merge 36 commits into
base: starting-point
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
fa66232
Update webpack.config.js
Jun 13, 2015
e1907d6
Merge pull request #20 from xtrasmal/patch-1
mgonto Jun 15, 2015
b4dc28d
chore: update to alpha 29
PatrickJS Jul 7, 2015
1f3c37e
Merge pull request #24 from gdi2290/alpha-29-update
mgonto Jul 7, 2015
6eb299a
Update Readme.md
mgonto Jul 7, 2015
92203ee
Update to Angular 2.0.0-alpha.30
Jul 8, 2015
8c15345
Merge pull request #25 from NathanWalker/master
mgonto Jul 8, 2015
f2d440b
Update Readme.md
mgonto Jul 24, 2015
4d97d19
chore(dependencies): updated to latest and made immutable
valorkin Oct 19, 2015
fc56f85
chore(start): updated ng2 0.44
valorkin Oct 19, 2015
9aa60d3
feat(backend): added backend
valorkin Oct 19, 2015
52018bf
chore(start): added npm command to start server
valorkin Oct 19, 2015
477b1ca
chore(traceur): removed, angular2 doesn't need it anymore
valorkin Oct 19, 2015
bd00b5a
chore(auth): redirect to /login if not authenticated
valorkin Oct 19, 2015
4fdaabe
chore(ui): styles fixed
valorkin Oct 19, 2015
8a9d63b
chore(navigation): navigation fixed
valorkin Oct 19, 2015
78ecb66
Merge pull request #38 from valor-software/master
mgonto Oct 19, 2015
9a80ef0
(fix) Update to work with agular2 beta 0
chenkie Jan 8, 2016
2eb9dc2
(fix) Proper error handling in HTTP requests
chenkie Jan 8, 2016
aad6352
Merge pull request #40 from chenkie/master
chenkie Jan 8, 2016
fc3c035
Logical precedence problem fixed
neilyoung Jan 11, 2016
fa4ad60
Readme and license fix
Jan 12, 2016
7f9b43d
Merge pull request #47 from aguerere/fix-issue46-license-and-readme
chenkie Jan 14, 2016
f2a7166
Update LoggedInOutlet.ts
Jan 20, 2016
5ed9d2a
supress pre-built javascript message
enaukkarinen Feb 5, 2016
8161e67
Removed no trailing comma from tslint. Closes #55.
chenkie Feb 26, 2016
c043d04
Merge pull request #53 from enaukkarinen/prebuilt-message-supress
chenkie Feb 26, 2016
0bb7148
Updated to Angular 2 beta 9
chenkie Mar 11, 2016
91f67a3
Merge pull request #49 from MasterKale/master
chenkie Mar 27, 2016
29f251c
Merge pull request #45 from neilyoung/master
chenkie Apr 18, 2016
4ed4b9c
Updated to rc.1. Closes #64.
chenkie May 18, 2016
0a3bc73
Update to rc.3
chenkie Jun 24, 2016
a87294d
Updated license
chenkie Jun 24, 2016
4474a12
Routes formatting
chenkie Jun 24, 2016
d7c6052
Upgrade to Angular 2 final and update articles section in readme
sonicoder86 Oct 2, 2016
3d5f962
Merge pull request #77 from blacksonic/master
chenkie Oct 4, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ build/Release
ehthumbs.db
Icon?
Thumbs.db
.idea

# Node Files #
node_modules
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# v0.0.1 - Update to Angular 2 Beta (2016-01-07)

* Upgraded to work with Angular 2 Beta 0
* Removed Fetch API in favor of Angular 2 Http
* Included [angular2-jwt](https://github.com/auth0/angular2-jwt) for authenticated API calls

3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 PatrickJS
Copyright (c) 2015-2016 Auth0, Inc. <[email protected]> (http://auth0.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

187 changes: 21 additions & 166 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,179 +1,34 @@
<p align="center">
<img src="https://res.cloudinary.com/angularclass/image/upload/v1431925418/webpackAndangular2_dwhus9.png" alt="Webpack and Angular 2" width="500" height="320"/>
</p>
# Angular 2: Authentication sample.

# Angular2 Webpack Starter [![Join the chat at https://gitter.im/angular-class/angular2-webpack-starter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/angular-class/angular2-webpack-starter?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
This sample shows how to create an angular 2 app that:
* Has **lots of different routes**
* Performs **authentication with JWTs**
* **Calls APIs** authenticated and not.
* Extends the **RouterOutlet** for route pipeline changes.

> A starter kit featuring [Angular 2](https://angular.io) ([Router](https://angular.io/docs/js/latest/api/router/), [Forms](https://angular.io/docs/js/latest/api/forms/), [Services](https://gist.github.com/gdi2290/634101fec1671ee12b3e#_follow_@AngularClass_on_twitter)), [TypeScript](http://www.typescriptlang.org/), and [Webpack](http://webpack.github.io/) by [AngularClass](https://angularclass.com).
You can **learn more about how it works in the following blogposts**

> If you're looking for Angular 1.x please use [NG6-starter](https://github.com/angular-class/NG6-starter)
* [Angular 2 Authentication Tutorial](https://auth0.com/blog/angular-2-authentication/)
* [Protecting Routes using Guards in Angular 2](http://blog.thoughtram.io/angular/2016/07/18/guards-in-angular-2.html)
* [Angular 2 authentication revisited](https://medium.com/@blacksonic86/angular-2-authentication-revisited-611bf7373bf9)

This repo serves as an extremely minimal starter for anyone looking to get up and running with Angular 2 and TypeScript. Using a [Webpack](http://webpack.github.io/) for building our files and assisting with boilerplate.
* Best practice in file organization for Angular 2.
* Ready to go build system using Webpack for working with TypeScript.
## Running it

### Quick start
> Clone/Download the repo then edit `app.ts` inside [`/src/app/components/app.ts`](/src/app/components/app.ts)
Clone this repository as well as [the server](https://github.com/auth0/nodejs-jwt-authentication-sample) for this example.

```bash
$ npm start # then open your browser and go to http://localhost:8080
```
First, run the server app in the port `3001`.

Then, run `npm install` on this project and run `npm start` to start the app. Then just navigate to [http://localhost:3000](http://localhost:3000) :boom:
Use `npm run server` to run API server.

## File Structure
We use the component approach in our starter. This is the new standard for developing Angular apps and a great way to ensure maintainable code by encapsulation of our behavior logic. A component is basically a self contained app usually in a single file or a folder with each concern as a file: style, template, specs, e2e, and component class. Here's how it looks:
```
angular2-webpack-starter/
├──public/ * static assets are served here
│ ├──lib/ * static libraries
│ │ └──traceur-runtime.min.js * ignore this file. This is needed to polyfill the browser to for ES6 features to similarly
│ │
│ ├──favicon.ico * replace me with your own favicon.ico
│ ├──service-worker.js * ignore this. Web App service worker that's not complete yet
│ ├──robots.txt * for search engines to crawl your website
│ ├──human.txt * for humans to know who the developers are
│ │
│ └──index.html * Index.html: where we place our script tags
├──src/ * our source files that will be compiled to javascript
│ ├──app/ * WebApp folder
│ │ ├──bootstrap.ts * entry file for app
│ │ │
│ │ ├──components/ * where most of components live
│ │ │ ├──todo.ts * an example of a component using a service and forms
│ │ │ ├──dashboard.ts * a simple Component with a simple Directive example
│ │ │ │
│ │ │ ├──home/ * example component as a folder
│ │ │ │ ├──home.ts * how you would require your template and style files
│ │ │ │ ├──home.css * simple css file for home styles
│ │ │ │ └──home.html * simple html file for home template
│ │ │ │
│ │ │ └──app.ts * App.ts: entry file for components
│ │ │
│ │ ├──services/ * where we keep our services used throughout our app
│ │ │ ├──TodoService.ts * an example of a simple service
│ │ │ └──services.ts * where we gather our injectables from our services
│ │ │
│ │ └──directives/ * where we keep our directives used throughout our app
│ │ ├──Autofocus.ts * another simple directive to fix a problem with the router
│ │ └──directives.ts * where we gather our directives from our directives
│ │
│ └──common/ * where common files used throughout our app
│ ├──shadowDomInjectables.ts * determind if the user is on chrome and use ShadowDom
│ ├──jitInjectables.ts * turn on Just-In-Time Change Detection
│ ├──formInjectables.ts * services exported by angular/forms which is the FormBuilder
│ └──BrowserDomAdapter.ts * ignore this. we need to set the DomAdapter to the browser
├──typings/ * where tsd defines it's types definitions
│ ├──_custom/ * where we define our custom types
│ │ ├──ng2.d.ts * where we patch angular2 types with our own types until it's fixed
│ │ └──custom.d.ts * we include all of our custom types here
│ │
│ ├──angular2/
│ │ └──angular2.d.ts * our Angular 2 type definitions
│ │
│ ├──es6-promise/
│ │ └──es6-promise.d.ts * ES6 promises type definitions
│ │
│ ├──rx/
│ │ ├──rx-lite.d.ts * rx-lite type definitions
│ │ └──rx.d.ts * rx type definitions
│ │
│ └──tsd.d.ts.ts * our main file for all of our type definitions
├──tsconfig.json * config that webpack uses for typescript
├──tsd.json * config that tsd uses for managing it's definitions
├──package.json * what npm uses to manage it's dependencies
└──webpack.config.js * our webpack config
```
## Issue Reporting

# Getting Started
## Dependencies
What you need to run this app:
* `node` and `npm` (`brew install node`)
* Ensure you're running the latest versions Node `v0.12.2`+ and NPM `2.10.0`+
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues.

Once you have those, you should install these globals with `npm install -global`:
* `webpack` (`npm install -global webpack`)
* `webpack-dev-server` (`npm install -global webpack-dev-server`)
## Author

## Installing
* `fork` this repo
* `clone` your fork
* `npm install` to install all dependencies
* `npm run server` to start the server
[Auth0](auth0.com)

## Running the app
After you have installed all dependencies you can now run the app. Run `npm server` to start a local server using `webpack-dev-server` which will watch, build (in-memory), and reload for you. The port will be displayed to you as `http://localhost:8080`.

### server
```bash
$ npm run server
```
## License

### build files
```bash
$ npm run build
```

### watch and build files
```bash
$ npm run watch
```

# TypeScript
> To take full advantage of TypeScript with autocomplete you would have to install it globally and use an editor with the correct TypeScript plugins.

## Use latest TypeScript compiler
TypeScript 1.5 beta includes everything you need. Make sure to upgrade, even if you installed TypeScript previously.

$ npm install -global typescript@^1.5.0-beta

## .d.ts Typings
The typings in `typings/` are partially autogenerated, partially hand
written. All the symbols should be present, but probably have wrong paramaters
and missing members. Modify them as you go.

$ npm install -global tsd
> You may need to require `reference path` for your editor to autocomplete correctly
```
/// <reference path="../../typings/tsd.d.ts" />
/// <reference path="../custom_typings/ng2.d.ts" />
```
Otherwise including them in `tsd.json` is prefered

## Use a TypeScript-aware editor
We have good experience using these editors:

* [Visual Studio Code](https://code.visualstudio.com/)
* [Webstorm 10](https://www.jetbrains.com/webstorm/download/)
* [Atom](https://atom.io/) with [TypeScript plugin](https://atom.io/packages/atom-typescript)
* [Sublime Text](http://www.sublimetext.com/3) with [Typescript-Sublime-Plugin](https://github.com/Microsoft/Typescript-Sublime-plugin#installation)

## Frequently asked questions
* Why we are using traceur? This is due to Angular 2 not being fully migrated to TypeScript and will be removed soon.
* What's the current browser support for Angular 2 Alpha? as of version 2.0.0-alpha.26: Chrome (43, 44, 45), Firefox (37, 39, 40), IE 11, Safari 8, iOS 8, Android 5.1 (Chrome Mobile 39).
* What is the TypeScript warning "Value of type 'typeof Directive' is not callable. Did you mean to include 'new'?"? This is an error with the typings defined in DefinitelyTyped (please ignore until it's fixed)

### Todo
- [ ] production/development environments
- [ ] testing
- [ ] e2e
- [ ] production services examples
- [ ] hot-component-reloading

# Starter Kit Support and Questions
> Contact us anytime for anything about this repo

* [Gitter: angular-class/angular2-webpack-starter](https://gitter.im/angular-class/angular2-webpack-starter)
* [Twitter: @AngularClass](https://twitter.com/AngularClass)

___

enjoy — **AngularClass**

<br><br>

[![AngularClass](https://angularclass.com/images/ng-crown.svg "Angular Class")](https://angularclass.com)
##[AngularClass](https://angularclass.com)
> Learn Angular in 2 days from the best
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.
2 changes: 2 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.env
50 changes: 50 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# NODE TODO API

This is a NodeJS full API that you can use to test with your SPAs or Mobile apps.

## How to use it

This service is deployed in Heroku and saves the TODOs in memory, so once the dyno dies, all the todos are removed.

It's deployed on [http://auth0-todo-test-api.herokuapp.com/](http://auth0-todo-test-api.herokuapp.com/)

## Available APIs

### Open API

The Open API lets anyone do CRUD operation on a set of TODOs. This means that you can add a TODO and then John Doe can delete it.

Available methods:

* **POST /api/open/todos**: Adds a new TODO
* **PUT /api/open/todos/:id**: Updates the TODO with id `id`
* **GET /api/open/todos/:id**: Returns the TODO with id `id`
* **DELETE /api/open/todos/:id**: Deletes the TODO with id `id`
* **GET /api/open/todos**: Gets all fo the TODOs

### User based API

You can use this API to save TODO items for a particular user. For that, you need to use Auth0 to get the `id_token` (JWT) and send it in every request as part of the `Authorization` header.

This server validates JWT from the following account:

* **Domain**: `samples.auth0.com`
* **ClientID**: `BUIJSW9x60sIHBw8Kd9EmCbj8eDIFxDC`

Available methods:

* **POST /api/todos**: Adds a new TODO
* **PUT /api/todos/:id**: Updates the TODO with id `id`
* **GET /api/todos/:id**: Returns the TODO with id `id`
* **DELETE /api/todos/:id**: Deletes the TODO with id `id`
* **GET /api/todos**: Gets all fo the TODOs

## Running this for your Auth0 account

If you want, you can run this server for YOUR Auth0 account. For that, you just need to create a `.env` file and set the `AUTH0_CLIENT_ID` and `AUTH0_CLIENT_SECRET` variables with the information from your account:

````bash
AUTH0_CLIENT_ID=YourClientId
AUTH0_CLIENT_SECRET=YourClientSecret
````

8 changes: 8 additions & 0 deletions backend/anonymous-routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var express = require('express'),
quoter = require('./quoter');

var app = module.exports = express.Router();

app.get('/api/random-quote', function(req, res) {
res.status(200).send(quoter.getRandomOne());
});
3 changes: 3 additions & 0 deletions backend/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"secret": "ngEurope rocks!"
}
35 changes: 35 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "chuck-norris-quotes-api",
"version": "0.1.0",
"description": "Chuck Norris Quotes API",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/auth0/angular2-authentication-sample"
},
"keywords": [
"jwt",
"auth0"
],
"author": "Martin Gontovnikas",
"license": "MIT",
"bugs": {
"url": "https://github.com/auth0/in-memory-todo/issues"
},
"homepage": "https://github.com/auth0/in-memory-todo",
"dependencies": {
"body-parser": "^1.15.0",
"compression": "^1.6.1",
"cors": "^2.7.1",
"dotenv": "^0.4.0",
"errorhandler": "^1.4.3",
"express": "^4.13.4",
"express-jwt": "^0.3.2",
"jsonwebtoken": "^1.3.0",
"lodash": "^2.4.2",
"morgan": "^1.7.0"
}
}
16 changes: 16 additions & 0 deletions backend/protected-routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var express = require('express'),
jwt = require('express-jwt'),
config = require('./config'),
quoter = require('./quoter');

var app = module.exports = express.Router();

var jwtCheck = jwt({
secret: config.secret
});

app.use('/api/protected', jwtCheck);

app.get('/api/protected/random-quote', function(req, res) {
res.status(200).send(quoter.getRandomOne());
});
7 changes: 7 additions & 0 deletions backend/quoter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var quotes = require('./quotes.json');

exports.getRandomOne = function() {
var totalAmount = quotes.length;
var rand = Math.ceil(Math.random() * totalAmount);
return quotes[rand];
}
Loading