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

Release 4.1.0 #71

Merged
merged 38 commits into from
Jul 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
319066a
Change rubocop configuration
Jun 7, 2016
4b288ea
Fix Rubocop issues
Jun 7, 2016
d1b72ed
Resource Servers Endpoint
Jun 7, 2016
71f0e83
Ignore unlink user test
Jun 10, 2016
2cea1fb
Add unit test for resource servers name
Jun 10, 2016
4173eae
Logs Endpoint Documentation Review
fleko Jun 9, 2016
3f717a4
Add wait helper + Refactor logs unit tests
Jun 10, 2016
deb193b
Update Rubocop
Jun 13, 2016
85ceaa3
Add spec for log method to validate the log_id
Jun 13, 2016
ede23b3
Change exception type to InvalidParameter
Jun 14, 2016
e70e241
API endpoints review
fleko Jun 10, 2016
a176a02
Add user_logs method to users endpoint
fleko Jun 13, 2016
79dc00e
Fix for send_verification_email issue
fleko Jun 13, 2016
f7e06a1
Rubocop fixes v0.40.0
fleko Jun 13, 2016
a017ff7
Add checks for per_page and sort parameters
fleko Jun 15, 2016
b1662be
Add client grants endpoints with corresponding unit and integration t…
fleko Jun 14, 2016
0d23fd3
Add User Blocks endpoints
Jun 9, 2016
78a01ed
Block user before each user_blocks integration test
Jun 17, 2016
e8ba5dc
Allow httparty_proxy delete method to support query strings
Jun 21, 2016
892ad46
Refactor user_blocks get and delete to use httproxy methods
Jun 21, 2016
28ff64b
Add Device Credentials endpoints and tests
fleko Jun 16, 2016
297cc9a
Fix Rubocop Issues
Jun 23, 2016
24d278d
Updated address
jgelsey Jun 18, 2016
6ce9479
Migrate from HTTParty to rest-client.
Jun 30, 2016
1c4bf7a
Add Rack version to the Gem file
Jul 1, 2016
aa57e52
Fix Impersonate method
Jun 30, 2016
b95b598
Add Integration Test to Authentication Endpoints - Impersonate
Jun 30, 2016
7c83f7a
Refactor tests to use the new proxy
Jul 4, 2016
4ed483d
Default API v2
Jul 4, 2016
6fbf4d2
Fix response type in Authorization Endpoints
Jul 5, 2016
47fc48b
Add authentication integration tests.
Jul 7, 2016
e768f79
Fix Rubocop Issues + Unit Tests
Jul 11, 2016
fb9be6f
adds obtain_user_token method to authentication endpoints
fleko Jul 7, 2016
89bb6a4
Fix authorization url parameter name error in unit tests
fleko Jul 15, 2016
46c38cf
Merge remote-tracking branch 'upstream/master'
Jul 19, 2016
7a09853
Add timeout example to Readme.md
Jul 21, 2016
9507df4
Fix ticket endpoint with mandatory password.
Jul 21, 2016
1c4e820
Fix ticket endpoint with mandatory password.
ignaciojonas Jul 21, 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
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
inherit_from: .rubocop_todo.yml
Rails:
Enabled: true
AllCops:
RunRailsCops: true
Exclude:
- bin/**/*
- vendor/**/*
Expand Down
2 changes: 0 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 15

# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 121
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ Using [APIv2](https://auth0.com/docs/api/v2)
require "auth0"

auth0 = Auth0Client.new(
:client_id => "YOUR CLIENT ID"
:token => "YOUR JWT HERE",
:domain => "<YOUR ACCOUNT>.auth0.com"
:domain => "<YOUR ACCOUNT>.auth0.com"
)

puts auth0.get_users
Expand All @@ -40,7 +41,24 @@ require "auth0"
auth0 = Auth0Client.new(
:client_id => "YOUR CLIENT ID",
:client_secret => "YOUR CLIENT SECRET",
:domain => "<YOUR ACCOUNT>.auth0.com"
:domain => "<YOUR ACCOUNT>.auth0.com",
:api_version => "1"
)

puts auth0.get_users
```

### Timeout
You can setup a custom timeout in the Auth0Client. By default it is set to 10 minutes.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably seconds, not minutes, right?


```ruby
require "auth0"

auth0 = Auth0Client.new(
:client_id => "YOUR CLIENT ID"
:token => "YOUR JWT HERE",
:domain => "<YOUR ACCOUNT>.auth0.com",
:timeout => 15
)

puts auth0.get_users
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ begin
RuboCop::RakeTask.new(:rubocop)

require 'yard'
DOC_FILES = ['lib/auth0/api/v2/*.rb', 'lib/auth0/api/authentication_endpoints.rb']
DOC_FILES = ['lib/auth0/api/v2/*.rb', 'lib/auth0/api/authentication_endpoints.rb'].freeze

desc 'Build Documentation'
YARD::Rake::YardocTask.new(:documentation) do |t|
Expand Down
3 changes: 2 additions & 1 deletion auth0.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.require_paths = ['lib']

s.add_runtime_dependency 'httmultiparty', '~> 0.3.16'
s.add_runtime_dependency 'rest-client', '~> 1.8.0'

s.add_development_dependency 'rake', '~> 10.4'
s.add_development_dependency 'fuubar', '~> 2.0'
Expand All @@ -28,6 +28,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'pry-nav', '~> 0.2.4'
s.add_development_dependency 'rspec', '~> 3.1', '>= 3.1.0'
s.add_development_dependency 'rack-test', '~> 0.6'
s.add_development_dependency 'rack', '~> 1.6.4'
s.add_development_dependency 'simplecov', '~> 0.9'
s.add_development_dependency 'faker', '~> 1.4'
s.add_development_dependency 'yard', '~> 0.8'
Expand Down
2 changes: 1 addition & 1 deletion examples/ruby-api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ source 'http://rubygems.org'
# gem "rails"
gem 'sinatra', '~> 1.4'
gem 'jwt', '~> 1.5'
gem 'dotenv'
gem 'dotenv'
2 changes: 1 addition & 1 deletion examples/ruby-api/config.ru
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require './main'
run Sinatra::Application
run Sinatra::Application
28 changes: 11 additions & 17 deletions examples/ruby-api/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,20 @@
Dotenv.load '.env'
set :show_exceptions, false


class InvalidTokenError < StandardError;
class InvalidTokenError < StandardError
end

def validate_token(env)
auth0_client_id = ENV['AUTH0_CLIENT_ID']
auth0_client_secret = ENV['AUTH0_CLIENT_SECRET']
authorization = env['HTTP_AUTHORIZATION']

raise InvalidTokenError if authorization.nil?

token = authorization.split(' ').last
decoded_token = JWT.decode(token,
JWT.base64url_decode(auth0_client_secret))

raise InvalidTokenError if auth0_client_id != decoded_token[0]['aud']
'You get this only if authenticated'
rescue JWT::DecodeError
raise InvalidTokenError
end
auth0_client_id = ENV['AUTH0_CLIENT_ID']
auth0_client_secret = ENV['AUTH0_CLIENT_SECRET']
authorization = env['HTTP_AUTHORIZATION']
raise InvalidTokenError if authorization.nil?
decoded_token = JWT.decode(authorization.split(' ').last, JWT.base64url_decode(auth0_client_secret))
raise InvalidTokenError if auth0_client_id != decoded_token[0]['aud']
'You get this only if authenticated'
rescue JWT::DecodeError
raise InvalidTokenError
end

error InvalidTokenError do
'Invalid token'
Expand Down
12 changes: 5 additions & 7 deletions examples/ruby-on-rails-api/Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', :groups => [:development, :test]
gem 'sqlite3', groups: [:development, :test]

gem 'pg'
# Use SCSS for stylesheets
Expand All @@ -23,16 +22,15 @@ gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.4.1'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.1', group: :doc
gem 'sdoc', '~> 0.4.1', group: :doc
# knock dependency
gem 'knock', '~> 1.4.2'

#Dot env
gem 'dotenv-rails', :groups => [:development, :test]

# Dot env
gem 'dotenv-rails', groups: [:development, :test]

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
gem 'spring', group: :development

gem 'pry', group: [:development, :test]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Application Controller
class ApplicationController < ActionController::Base
include Knock::Authenticable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Ping Controller
class PingController < ApplicationController

def ping
render text: "All good. You don't need to be authenticated to call this"
end

end
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Secured ping Controller
class SecuredPingController < ApplicationController
before_action :authenticate

def ping
render :json => {
:message => "All good. You only get this message if you're authenticated.",
:user => @current_user
}
render json: {
message: "All good. You only get this message if you're authenticated.",
user: @current_user
}
end

end
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Application Helper
module ApplicationHelper
end
16 changes: 8 additions & 8 deletions examples/ruby-on-rails-api/bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
require 'pathname'

# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)

Dir.chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file:

puts "== Installing dependencies =="
system "gem install bundler --conservative"
system "bundle check || bundle install"
puts '== Installing dependencies =='
system 'gem install bundler --conservative'
system 'bundle check || bundle install'

# puts "\n== Copying sample files =="
# unless File.exist?("config/database.yml")
# system "cp config/database.yml.sample config/database.yml"
# end

puts "\n== Preparing database =="
system "bin/rake db:setup"
system 'bin/rake db:setup'

puts "\n== Removing old logs and tempfiles =="
system "rm -f log/*"
system "rm -rf tmp/cache"
system 'rm -f log/*'
system 'rm -rf tmp/cache'

puts "\n== Restarting application server =="
system "touch tmp/restart.txt"
system 'touch tmp/restart.txt'
end
2 changes: 1 addition & 1 deletion examples/ruby-on-rails-api/config.ru
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
1 change: 0 additions & 1 deletion examples/ruby-on-rails-api/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

module Auth0RorapiSample
class Application < Rails::Application

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
Expand Down
2 changes: 1 addition & 1 deletion examples/ruby-on-rails-api/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
config.eager_load = false

# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_files = true
config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'

# Show full error reports and disable caching.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Be sure to restart your server when you modify this file.

Rails.application.config.action_dispatch.cookies_serializer = :json
Rails.application.config.action_dispatch.cookies_serializer = :json
10 changes: 3 additions & 7 deletions examples/ruby-on-rails-api/config/initializers/knock.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'base64'
Knock.setup do |config|

## Current user retrieval when validating token
## --------------------------------------------
##
Expand All @@ -14,7 +13,7 @@
# !!!
# This is only to make the example test cases pass, you should use a real
# user model in your app instead.
config.current_user_from_token = -> (claims) {{ id: claims['sub'] }}
config.current_user_from_token = -> (claims) { { id: claims['sub'] } }

## Expiration claim
## ----------------
Expand All @@ -24,7 +23,6 @@
## Default:
# config.token_lifetime = 1.day


## Audience claim
## --------------
##
Expand All @@ -37,7 +35,6 @@
## If using Auth0, uncomment the line below
config.token_audience = -> { Rails.application.secrets.auth0_client_id }


## Signature key
## -------------
##
Expand All @@ -47,11 +44,10 @@
# config.token_secret_signature_key = -> { Rails.application.secrets.secret_key_base }

## If using Auth0, uncomment the line below
#config.token_secret_signature_key = -> { JWT.base64url_decode Rails.application.secrets.auth0_client_secret }
config.token_secret_signature_key = -> {
# config.token_secret_signature_key = -> { JWT.base64url_decode Rails.application.secrets.auth0_client_secret }
config.token_secret_signature_key = lambda {
secret = Rails.application.secrets.auth0_client_secret
secret += '=' * (4 - secret.length.modulo(4))
Base64.decode64(secret.tr('-_', '+/'))
}

end
1 change: 0 additions & 1 deletion examples/ruby-on-rails-api/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Rails.application.routes.draw do

get 'ping' => 'ping#ping'
get 'secured/ping' => 'secured_ping#ping'
# The priority is based upon order of creation: first created -> highest priority.
Expand Down
1 change: 0 additions & 1 deletion examples/ruby-on-rails-api/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 0) do

end
4 changes: 1 addition & 3 deletions examples/ruby-on-rails-api/test/ping_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
require 'test_helper'

# Ping Controller Tests
class PingControllerTest < ActionController::TestCase

test 'responds with success' do
get :ping
assert_response :success
end

end
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'test_helper'

# Secure Ping Controller Test
class SecuredPingControllerTest < ActionController::TestCase

def with_a_valid_token
@user = { id: 1 }
@token = Knock::AuthToken.new(payload: { sub: @user[:id] }).token
Expand Down
19 changes: 11 additions & 8 deletions examples/ruby-on-rails-api/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
# Active Support
class ActiveSupport
# Test Case
class TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all

class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all

# Add more helper methods to be used by all tests here...
# Add more helper methods to be used by all tests here...
end
end
Loading