Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
rotate tokens and update copyright
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Abbott committed Jan 25, 2020
1 parent 8a018e3 commit e575b4c
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 170 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2019 Jason Abbott
Copyright (c) 2020 Jason Abbott

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
222 changes: 125 additions & 97 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"@toba/feed": "^3.1.1",
"@toba/handlebars": "^2.1.0",
"@toba/node-tools": "^1.5.3",
"@trailimage/flickr-provider": "^3.2.0",
"@trailimage/google-provider": "^2.5.0",
"@trailimage/flickr-provider": "^3.2.2",
"@trailimage/google-provider": "^2.5.1",
"@trailimage/models": "^3.2.2",
"compression": "^1.7.0",
"express": "^4.16.0",
Expand Down
103 changes: 52 additions & 51 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,82 @@
import { blockSpamReferers } from '@toba/block-spam-referer';
import compress from 'compression';
import Express from 'express';
import { ExpressHandlebars } from '@toba/handlebars';
import * as path from 'path';
import { postProvider } from '@trailimage/flickr-provider';
import { mapProvider } from '@trailimage/google-provider';
import { config as modelConfig, blog } from '@trailimage/models';
import { config } from './config';
import { blockSpamReferers } from '@toba/block-spam-referer'
import compress from 'compression'
import Express from 'express'
import { ExpressHandlebars } from '@toba/handlebars'
import * as path from 'path'
import { postProvider } from '@trailimage/flickr-provider'
import { mapProvider } from '@trailimage/google-provider'
import { config as modelConfig, blog } from '@trailimage/models'
import { config } from './config'
import {
Layout,
addTemplateMethods,
requireSSL,
checkCacheReset,
sortCategories
} from './views/';
import { route } from './routes';
} from './views/'
import { route } from './routes'

const root = path.join(__dirname, '..');
const root = path.join(__dirname, '..')

if (process.argv.includes('--serve')) {
configureModels();
createWebService();
configureModels()
createWebService()
}

export function configureModels() {
postProvider.configure(config.providers.post);
mapProvider.configure(config.providers.map);
postProvider.configure(config.providers.post)
mapProvider.configure(config.providers.map)

modelConfig.site = config.site;
modelConfig.owner = config.owner;
modelConfig.subtitleSeparator = config.posts.subtitleSeparator;
modelConfig.maxPhotoMarkersOnMap = config.providers.map.maxMarkers;
modelConfig.providers.post = postProvider;
modelConfig.providers.map = mapProvider;
modelConfig.site = config.site
modelConfig.owner = config.owner
modelConfig.subtitleSeparator = config.posts.subtitleSeparator
modelConfig.maxPhotoMarkersOnMap = config.providers.map.maxMarkers
modelConfig.providers.post = postProvider
modelConfig.providers.map = mapProvider
modelConfig.artistsToNormalize = new RegExp(
config.posts.artistNames.join('|')
);
)
}

async function createWebService() {
const app = Express();
const port = process.env['PORT'] || 3000;
const app = Express()
const port = process.env['PORT'] || 3000

console.info(
`Starting ${
config.isProduction ? 'production' : 'development'
} application`
);
)

defineViews(app);
defineViews(app)

if (false) {
//config.needsAuth) {
if (
false &&
!(postProvider.isAuthenticated && mapProvider.isAuthenticated)
) {
// must authenticate before normal routes are available
route.authentication(app);
app.listen(port);
console.info(`Listening for authentication on port ${port}`);
route.authentication(app)
app.listen(port)
console.info(`Listening for authentication on port ${port}`)
} else {
if (config.requireSSL) {
app.use(requireSSL);
}
app.use(blockSpamReferers);
app.use(checkCacheReset);
if (config.requireSSL) app.use(requireSSL)

app.use(blockSpamReferers)
app.use(checkCacheReset)
// https://github.com/expressjs/compression/blob/master/README.md
app.use(compress());
app.use(Express.static(path.join(root, 'public')));
app.use(compress())
app.use(Express.static(path.join(root, 'public')))

await blog.load();
await blog.load()

if (blog.loaded) {
// blog must be loaded before routes are defined
sortCategories(blog);
route.standard(app);
app.listen(port);
console.info(`Listening on port ${port}`);
sortCategories(blog)
route.standard(app)
app.listen(port)
console.info(`Listening on port ${port}`)
} else {
console.error('Blog data failed to load. Stopping application.');
console.error('Blog data failed to load. Stopping application.')
}
}
}
Expand All @@ -85,15 +86,15 @@ async function createWebService() {
* @see http://mustache.github.com/mustache.5.html
*/
function defineViews(app: Express.Application) {
const viewPath = path.join(root, 'views');
const viewPath = path.join(root, 'views')
const ehb = new ExpressHandlebars({
defaultLayout: Layout.Main!
});
})

// http://expressjs.com/4x/api.html#app-settings
app.set('views', viewPath);
app.set('view engine', ehb.fileExtension);
app.engine(ehb.fileExtension, ehb.renderer);
app.set('views', viewPath)
app.set('view engine', ehb.fileExtension)
app.engine(ehb.fileExtension, ehb.renderer)

addTemplateMethods(ehb);
addTemplateMethods(ehb)
}
2 changes: 1 addition & 1 deletion src/config/map-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const mapProvider: ProviderConfig = {
apiKey: '',
clientID: env('GOOGLE_CLIENT_ID'),
secret: env('GOOGLE_SECRET'),
callback: 'http://www.' + domain + '/auth/google',
callback: 'https://www.' + domain + '/auth/google',
token: {
access: env('GOOGLE_ACCESS_TOKEN'),
refresh: env('GOOGLE_REFRESH_TOKEN')
Expand Down
8 changes: 4 additions & 4 deletions src/config/post-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const postProvider: ProviderConfig = {
featureSets: [{ id: '72157632729508554', title: 'Ruminations' }],
api: {
userID: '60950751@N04',
appID: '72157631007435048',
appID: '72157712821709122',
timeZoneOffset: -7,
setPhotoSizes: [],
searchPhotoSizes: [Flickr.SizeCode.Square150],
Expand All @@ -44,10 +44,10 @@ export const postProvider: ProviderConfig = {
auth: {
apiKey: env('FLICKR_API_KEY'),
secret: env('FLICKR_SECRET'),
callback: 'http://www.' + domain + '/auth/flickr',
callback: 'https://www.' + domain + '/auth/flickr',
token: {
access: env('FLICKR_ACCESS_TOKEN'),
secret: env('FLICKR_TOKEN_SECRET')
access: process.env['FLICKR_ACCESS_TOKEN'],
secret: process.env['FLICKR_TOKEN_SECRET']
}
}
}
Expand Down
33 changes: 20 additions & 13 deletions src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ import { Page, Layout, view } from '../views/'
/**
* Redirect to authorization URL for unauthorized providers.
*/
export function main(_req: Request, res: Response) {
;[
modelConfig.providers.post,
modelConfig.providers.map,
modelConfig.providers.video
].forEach(async p => {
if (is.value<DataProvider<any>>(p) && !p.isAuthenticated) {
const url = await p.authorizationURL()
res.redirect(url)
return
}
})
export async function main(_req: Request, res: Response) {
try {
const urls = await Promise.all(
[
modelConfig.providers.post,
modelConfig.providers.map,
modelConfig.providers.video
]
.filter(p => is.value<DataProvider<any>>(p) && !p.isAuthenticated)
.map(p => p!.authorizationURL())
)
res.render(Page.Authorize, {
title: 'Provider Login Links',
urls,
layout: Layout.NONE
})
} catch (e) {
view.internalError(res, e)
}
}

export function postAuth(req: Request, res: Response) {
Expand Down Expand Up @@ -45,7 +52,7 @@ async function authCallback(
}
const token = await p.getAccessToken(req)
res.render(Page.Authorize, {
title: 'Flickr Access',
title: 'Provider Access',
token: token.access,
secret: token.secret,
layout: Layout.NONE
Expand Down
8 changes: 8 additions & 0 deletions views/authorize.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<div class="authorize content">
{{#if urls}}
<ul>
{{#urls}}
<li><a href="{{this}}">{{this}}</a></li>
{{/urls}}
</ul>
{{else}}
<h4>Access Token</h4>
<div>{{token}}</div>

<h4>Secret or Refresh Token</h4>
<div>{{secret}}</div>
{{/if}}
</div>
2 changes: 1 addition & 1 deletion views/partials/footer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</a>

<aside>
<p class="rights"><strong>Text, images and video are &#169; Copyright 2019 Jason Abbott. All Rights Reserved.</strong></p>
<p class="rights"><strong>Text, images and video are &#169; Copyright 2020 Jason Abbott. All Rights Reserved.</strong></p>
<p>Topographic background courtesy of the <a href='http://motoidaho.com/'>Idaho Adventure Motorcycling Club</a></p>
<p>Maps are &#169; Copyright <a href="https://www.mapbox.com/about/maps/">Mapbox</a>
and &#169; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>
Expand Down

0 comments on commit e575b4c

Please sign in to comment.