Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Add example Sinatra application #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -15,3 +15,4 @@ spec/reports
test/tmp
test/version_tmp
tmp
example/.powenv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As their's a example/.powenv.sample showing how to setup is environment variables with Pow I think not having this could quickly leak credentials to Git :/

Why don't you like it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, in that case might make more sense to put in the .gitignore inside example :)

2 changes: 2 additions & 0 deletions example/.powenv.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export ASANA_CLIENT_ID=""
export ASANA_CLIENT_SECRET=""
5 changes: 5 additions & 0 deletions example/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gem "sinatra"
gem "json"
gem "omniauth-asana"
35 changes: 35 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Asana OAuth Helper

Small sinatra application to help you get your OAuth Token for your Asana Application.
This is specially useful to play around Asana API.

## Usage

### Requirements:

[POW](http://pow.cx/) - To run this Sinatra application.
[Tunnelss](https://github.com/rchampourlier/tunnelss) - To use SSL

_Note: Tricks for [persiting SSL with Tunnelss over reboot](http://www.sebgrosjean.com/en/news/2014/2/9/rails-with-ssl-in-development-with-pow-and-tunnels)_

### 1) Install dependencies

```sh
bundle install
```

### 2) Setup your Asana Application credentials

```sh
cp .powenv.sample .powenv
```

Edit the `ASANA_CLIENT_ID` and `ASANA_CLIENT_SECRET` environment variables from the `.powenv` file.

### 3) Restart Pow

Make sure to restart Pow, using:

```sh
touch tmp/restart.txt
```
50 changes: 50 additions & 0 deletions example/asana_oauth_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require "sinatra"
require "json"
require "omniauth-asana"

use Rack::Session::Cookie

use OmniAuth::Builder do
provider :asana, ENV['ASANA_CLIENT_ID'], ENV['ASANA_CLIENT_SECRET']
end

get "/" do
<<-HTML
<html>
<head>
<style>
body {
text-align: center;
}

a {
display: inline-block;
padding: 10px 20px;
font-size: 16px;
color: #fff;
background-color: #1B57AA;
text-decoration: none;
border-radius: 4px;
margin: 100px auto 0;
}

a:hover {
background-color: #2b88dc;
}
</style>
</head>
<body>
<p><a href="/auth/asana">Sign in with Asana</a></p>
</body>
</html>
HTML
end

get "/auth/:provider/callback" do
request.env["omniauth.auth"].to_hash.to_json
end

get "/auth/failure" do
content_type "text/plain"
params[:message]
end
7 changes: 7 additions & 0 deletions example/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rubygems'
require 'bundler'
Bundler.setup

require './asana_oauth_helper'

run Sinatra::Application