Skip to content
This repository was archived by the owner on Jun 24, 2019. It is now read-only.

Commit ba6f299

Browse files
authored
Oauth Implemention for signingup with FB/Twitter and Github using Passport.js (#32)
* #10 - User signup using Facebook, Twitter and Github , implementation using passport.js * updating instructions for developers * Make login routes only in development mode. Handle cases when github settings are set to hide email. Log message for missing developer tokens in env. * create different end points for different environments * add condition to check if SSL certificates have been provided. * Externalize SSL Certs, Use Mongo for App sessions in Production. * fixed untracked files * added .env.sample and updated docs. * Set up CI with Azure Pipelines (#2) * Set up CI with Azure Pipelines * testing * testing * testing * testing * testing * added package.json * Update azure-pipelines.yml for Azure Pipelines * testing * testing * testing * added azure templates * updated build yaml * switched containers * fix build to acr * variables * fixed variable * build yaml
1 parent c0d6524 commit ba6f299

25 files changed

+4215
-965
lines changed

.babelrc

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
{
22
"passPerPreset": true,
3-
"presets": [ "@babel/preset-env" ],
3+
"presets": [
4+
"@babel/preset-env"
5+
],
46
"plugins": [
57
[
68
"babel-plugin-inline-import",
79
{
8-
"extensions": [ ".gql", ".graphql" ]
10+
"extensions": [".gql", ".graphql"]
911
},
1012
"@babel/plugin-transform-runtime"
1113
],
12-
"@babel/plugin-transform-arrow-functions"
14+
"@babel/plugin-transform-arrow-functions",
15+
["module-resolver", {
16+
"root": ["./src"]
17+
}]
1318
]
1419
}

.env.sample

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
PORT=3001
2+
WITH_SSL=true
3+
CERTS_DIR=
4+
SSL_KEY_FILENAME=
5+
SSL_CERT_FILENAME=
6+
DEV_HOSTNAME=api.codingcoach.dev
7+
PROD_HOSTNAME=api.codingcoach.io
8+
NODE_PATH=src/
9+
NODE_ENV=development
10+
RANDOM_TOKEN=c5XIN5sQMtrMxhQ9diQ0
11+
12+
MONGO_DB_URI=
13+
14+
LOGS_FOLDER=logs
15+
ERROR_LOG=err.log
16+
INFO_LOG=info.log
17+
WARNINGS_LOG=warnings.log
18+
19+
OAUTH_FACEBOOK_CLIENT_ID=
20+
OAUTH_FACEBOOK_CLIENT_SECRET=
21+
22+
OAUTH_TWITTER_CONSUMER_KEY=
23+
OAUTH_TWITTER_CONSUMER_SECRET=
24+
25+
OAUTH_GITHUB_CLIENT_ID=
26+
OAUTH_GITHUB_CLIENT_SECRET=

.eslintrc

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
"airbnb/base",
55
"plugin:import/errors"
66
],
7+
"settings": {
8+
"import/resolver": {
9+
"node": {
10+
"moduleDirectory": ["node_modules", "src/"]
11+
}
12+
}
13+
},
714
"rules": {
815
"no-use-before-define": 0,
916
"arrow-body-style": 0,
@@ -15,6 +22,10 @@
1522
"jest": true
1623
},
1724
"globals": {
18-
"client": true
25+
"client": true,
26+
"LOGS_FOLDER": true,
27+
"INFO": true,
28+
"ERROR": true,
29+
"WARN": true
1930
}
2031
}

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ dist/
66
.DS_Store
77
/coverage
88
.env
9+
logs/
10+
**/*.log
11+
production.server.crt
12+
production.server.key

OAUTH.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
### Implementing User signup on FE
2+
3+
The backend application has been configured to retrieve user profiles when the following endpoint is queried
4+
5+
#### Facebook
6+
```
7+
GET https://api.codingcoach.io/auth/facebook?code=<one-time code retrieved from FB in callback>
8+
```
9+
#### Twitter
10+
```
11+
GET https://api.codingcoach.io/auth/twitter?oauth_token=<one-time token retrieved from TWITTER in callback>&oauth_verifier=<one-time verifier retrieved from TWITTER in callback>
12+
```
13+
#### Github
14+
```
15+
GET https://api.codingcoach.io/auth/github?code=<one-time code retrieved from GITHUB in callback>
16+
```
17+
18+
While developing the server should be acessible as 'https://api.codingcoach.dev`
19+
20+
The JSON response of these calls will contain the saved user profile like this :
21+
```json
22+
{
23+
"failedLogin": {
24+
"numFailed": 0
25+
},
26+
"activationStatus": false,
27+
"_id": "",
28+
"email": "[email protected]",
29+
"firstName": "John",
30+
"lastName": "Doe",
31+
"github": {
32+
"id": "",
33+
"email": "[email protected]",
34+
"firstName": "John",
35+
"lastName": "Doe",
36+
"provider": "github",
37+
"accessToken": "",
38+
"username": "johndoe"
39+
},
40+
"__v": 0,
41+
"facebook": {
42+
"id": "",
43+
"email": "[email protected]",
44+
"firstName": "Jagdish",
45+
"lastName": "Doe Jane",
46+
"provider": "facebook",
47+
"accessToken": "",
48+
"refreshToken": null
49+
}
50+
}
51+
```

README.md

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
11
# Coding-Coach-api
22
[![Build Status](https://api.travis-ci.org/Coding-Coach/coding-coach-api.svg?branch=development)](https://travis-ci.org/Coding-Coach/coding-coach-api)
33

4-
## Getting Started
5-
The server can be run in two different modes: `development` and `production`
64

5+
# Important INSTRUCTIONS for Developers
6+
Copy `.env.sample` to `.env` as it contains the ENV configurations needed during bootstrapping the appliation. DO NOT commit the .env file.
7+
If you have changes that are need on bootstrap, add it to the `.env.sample` file, and ensure you have handled the missing values in your code.
8+
9+
You need to run the server in HTTPS Mode, to ensure you don't get conflicts in your browser.
10+
A `development.pem` has been provided in `src/certs`.
11+
12+
#### Mac Users
13+
Open Keychain Access and import the root certificate `development.pem` in `src/certs` to your System keychain. Then right click on `codingcoach` in Keychain and select `Get info`. Expand `Trust` and mark the certificate to `Always Trust`.
14+
15+
#### Linux Users
16+
Depending on your Linux distribution, you can use `trust`, `update-ca-certificates` or another command to mark the generated root certificate as trusted. [TODO: add detailed instructions].
17+
18+
#### Windows Users
19+
*No clues as how to do this at this point.*
20+
21+
Add an alias in your `/etc/hosts` for `codingcoach.dev`.
22+
23+
```
24+
# /etc/hosts
25+
# Host Database
26+
#
27+
# localhost is used to configure the loopback interface
28+
# when the system is booting. Do not change this entry.
29+
##
30+
127.0.0.1 localhost
31+
127.0.0.1 api.codingcoach.dev
32+
```
733
## Development
834
To run the server in `development`:
935
1. `yarn install` - This will install the node dependencies
@@ -12,8 +38,7 @@ To run the server in `development`:
1238
The server runs in watch mode so changes you make to the API will automatically restart the server
1339
with those changes.
1440

15-
GraphQL Playground at : http://localhost:3000/graphql
16-
Dummy Endpoint : http://localhost:3000/hello
41+
GraphQL Playground at : https://codingcoach.dev:3001/graphql
1742

1843
> Note that this does not start a MongoDB database, ensure an instance is running at `localhost:27017`.
1944

azure-pipelines.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
resources:
2+
- repo: self
3+
4+
pool:
5+
vmImage: Hosted Ubuntu 1604
6+
demands:
7+
- node
8+
- npm
9+
10+
variables:
11+
resourcegroup: 'coding-coach-rg'
12+
location: 'West Europe'
13+
registry: 'codingcoachacr'
14+
beimage: 'codingcoachbe'
15+
16+
steps:
17+
- task: AzureResourceGroupDeployment@2
18+
displayName: 'Azure Deployment:Create Or Update Resource Group action on $(resourcegroup)'
19+
inputs:
20+
azureSubscription: 'Free Trial (15d1a0f0-8a6b-470e-9cd2-eef5ba7c5a5a)'
21+
resourceGroupName: '$(resourcegroup)'
22+
location: '$(location)'
23+
csmFile: '$(System.DefaultWorkingDirectory)/azure-templates/container-registry-template.json'
24+
overrideParameters: '-registryName "$(registry)" -registryLocation "$(location)" -registrySku "Basic"'
25+
26+
- task: NodeTool@0
27+
displayName: 'Use Node 10'
28+
inputs:
29+
versionSpec: 10.x
30+
checkLatest: true
31+
32+
- task: Npm@1
33+
displayName: 'Install all dependencies'
34+
inputs:
35+
workingDir: '$(System.DefaultWorkingDirectory)'
36+
verbose: false
37+
38+
- task: Docker@1
39+
displayName: 'Build an image'
40+
inputs:
41+
azureSubscriptionEndpoint: 'Free Trial (15d1a0f0-8a6b-470e-9cd2-eef5ba7c5a5a)'
42+
azureContainerRegistry: '$(registry).azurecr.io'
43+
useDefaultContext: false
44+
buildContext: '$(System.DefaultWorkingDirectory)'
45+
imageName: '$(beimage):$(Build.BuildId)'
46+
47+
- task: Docker@1
48+
displayName: 'Publish an image'
49+
inputs:
50+
azureSubscriptionEndpoint: 'Free Trial (15d1a0f0-8a6b-470e-9cd2-eef5ba7c5a5a)'
51+
azureContainerRegistry: '$(registry).azurecr.io'
52+
command: 'Push an image'
53+
imageName: '$(beimage):$(Build.BuildId)'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"registryName": {
6+
"type": "String"
7+
},
8+
"registryLocation": {
9+
"type": "String"
10+
},
11+
"registrySku": {
12+
"defaultValue": "Standard",
13+
"type": "String"
14+
}
15+
},
16+
"resources": [{
17+
"type": "Microsoft.ContainerRegistry/registries",
18+
"sku": {
19+
"name": "[parameters('registrySku')]"
20+
},
21+
"name": "[parameters('registryName')]",
22+
"apiVersion": "2017-10-01",
23+
"location": "[parameters('registryLocation')]",
24+
"properties": {
25+
"adminUserEnabled": "true"
26+
}
27+
}]
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"webAppName": {
6+
"type": "String"
7+
},
8+
"hostingPlanName": {
9+
"type": "String"
10+
},
11+
"appInsightsLocation": {
12+
"type": "String"
13+
},
14+
"sku": {
15+
"defaultValue": "Standard",
16+
"type": "String"
17+
},
18+
"registryName": {
19+
"type": "String"
20+
},
21+
"imageName": {
22+
"type": "String"
23+
},
24+
"registryLocation": {
25+
"type": "String"
26+
},
27+
"registrySku": {
28+
"defaultValue": "Standard",
29+
"type": "String"
30+
},
31+
"startupCommand": {
32+
"defaultValue": "",
33+
"type": "String"
34+
}
35+
},
36+
"resources": [{
37+
"type": "Microsoft.Web/sites",
38+
"name": "[parameters('webAppName')]",
39+
"apiVersion": "2016-03-01",
40+
"location": "[resourceGroup().location]",
41+
"tags": {
42+
"[concat('hidden-related:', '/subscriptions/', subscription().subscriptionId,'/resourcegroups/', resourceGroup().name, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "empty"
43+
},
44+
"properties": {
45+
"name": "[parameters('webAppName')]",
46+
"siteConfig": {
47+
"appSettings": [{
48+
"name": "DOCKER_REGISTRY_SERVER_URL",
49+
"value": "[concat('https://', reference(concat('Microsoft.ContainerRegistry/registries/', parameters('registryName'))).loginServer)]"
50+
},
51+
{
52+
"name": "DOCKER_REGISTRY_SERVER_USERNAME",
53+
"value": "[listCredentials(concat('Microsoft.ContainerRegistry/registries/', parameters('registryName')), '2017-10-01').username]"
54+
},
55+
{
56+
"name": "DOCKER_REGISTRY_SERVER_PASSWORD",
57+
"value": "[listCredentials(concat('Microsoft.ContainerRegistry/registries/', parameters('registryName')), '2017-10-01').passwords[0].value]"
58+
},
59+
{
60+
"name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
61+
"value": "false"
62+
},
63+
{
64+
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
65+
"value": "[reference(resourceId('microsoft.insights/components/', parameters('webAppName')), '2015-05-01').InstrumentationKey]"
66+
}
67+
],
68+
"appCommandLine": "[parameters('startupCommand')]",
69+
"linuxFxVersion": "[concat('DOCKER|', reference(concat('Microsoft.ContainerRegistry/registries/', parameters('registryName'))).loginServer, '/', parameters('imageName'))]"
70+
},
71+
"serverFarmId": "[concat('/subscriptions/', subscription().subscriptionId,'/resourcegroups/', resourceGroup().name, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
72+
"hostingEnvironment": ""
73+
},
74+
"dependsOn": [
75+
"[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
76+
"[resourceId('microsoft.insights/components/', parameters('webAppName'))]"
77+
]
78+
},
79+
{
80+
"type": "Microsoft.ContainerRegistry/registries",
81+
"sku": {
82+
"name": "[parameters('registrySku')]"
83+
},
84+
"name": "[parameters('registryName')]",
85+
"apiVersion": "2017-10-01",
86+
"location": "[parameters('registryLocation')]",
87+
"properties": {
88+
"adminUserEnabled": "true"
89+
}
90+
},
91+
{
92+
"type": "Microsoft.Web/serverfarms",
93+
"sku": {
94+
"Tier": "[first(skip(split(parameters('sku'), ' '), 1))]",
95+
"Name": "[first(split(parameters('sku'), ' '))]"
96+
},
97+
"kind": "linux",
98+
"name": "[parameters('hostingPlanName')]",
99+
"apiVersion": "2016-09-01",
100+
"location": "[resourceGroup().location]",
101+
"properties": {
102+
"name": "[parameters('hostingPlanName')]",
103+
"workerSizeId": "0",
104+
"reserved": true,
105+
"numberOfWorkers": "1",
106+
"hostingEnvironment": ""
107+
}
108+
},
109+
{
110+
"type": "Microsoft.Insights/components",
111+
"name": "[parameters('webAppName')]",
112+
"apiVersion": "2014-04-01",
113+
"location": "[parameters('appInsightsLocation')]",
114+
"tags": {
115+
"[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', parameters('webAppName'))]": "Resource"
116+
},
117+
"properties": {
118+
"applicationId": "[parameters('webAppName')]",
119+
"Request_Source": "AzureTfsExtensionAzureProject"
120+
}
121+
}
122+
]
123+
}

0 commit comments

Comments
 (0)