Skip to content

Commit

Permalink
Store client ID in local.js: #33
Browse files Browse the repository at this point in the history
Link to the explanation of how to get a Google client ID for
authentication.  Save this ID in a config file.  Store the generated
client_id in the page and use it for signin.

Since the client-side javascript already needed to have this client_id,
I don't think that embedding it in the page is a problem.
  • Loading branch information
cecilia-donnelly committed Feb 2, 2016
1 parent 1c1ed11 commit 3a45b6a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ _In order for those endpoints to function correctly, you must also create a loca
$> cp config/env/local.js.example config/env/local.js
$> vi config/env/local.js
```
Generate a Google Client ID as described in the [OpenHMIS INSTALL doc](https://github.com/PCNI/OpenHMIS/blob/master/INSTALL.md) and store it in your new `local.js` file.

3. Install npm dependencies

Expand Down
9 changes: 9 additions & 0 deletions app/controllers/core.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
/**
* Module dependencies.
*/

exports.index = function(req, res) {
var local = {}
try {
local = require('../../config/env/local');
} catch (e) {
console.log("IMPORTANT: You have not set up your local configuration in /config/env/local.js");
}

res.render('index', {
user: req.user || null,
client_id: local.app.client_id,
request: req
});
};
1 change: 1 addition & 0 deletions app/views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ html(lang="en")
.container
div#logo
img(src='img/OpenHMIS-logo.jpg')
input#google_id(name='google_id', type='hidden', value='#{client_id}')
div#search
h1 Client Search
form#searchForm
Expand Down
3 changes: 2 additions & 1 deletion config/env/local.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = {
app: {
title: 'OpenHMIS Intake',
description: 'Add new clients to an OpenHMIS API compliant system',
keywords: 'openhmis, intake'
keywords: 'openhmis, intake',
client_id: '__YOUR_CLIENT_ID__.apps.googleusercontent.com'
},
port: 3000,

Expand Down
4 changes: 3 additions & 1 deletion public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1464,9 +1464,11 @@ $(function() {
}

function start() {
// get client id
var client_id = $("#google_id").val();
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: 'YOUR_CLIENT_ID.apps.googleusercontent.com',
client_id: client_id
});
});
}
Expand Down

0 comments on commit 3a45b6a

Please sign in to comment.