Skip to content

Commit

Permalink
Merge pull request #1012 from Amialc/ror_api_tutorial_update
Browse files Browse the repository at this point in the history
[update] Rails API tutorial fixes
  • Loading branch information
ntotten committed Mar 7, 2016
2 parents f3c13ff + b78809f commit bbe6420
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
24 changes: 19 additions & 5 deletions articles/server-apis/rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ Add this line to your application's Gemfile:
${snippet(meta.snippets.dependencies)}

And then execute:

$ bundle install
```
bundle install
```

Finally, run the install generator:

$ rails generate knock:install
```
rails generate knock:install
```

It will create the following initializer `config/initializers/knock.rb`.
This file contains all the informations about the existing configuration options.
Expand Down Expand Up @@ -117,9 +119,21 @@ config.token_audience = -> { Rails.application.secrets.auth0_client_id }
```

```ruby
config.token_secret_signature_key = -> { JWT.base64url_decode Rails.application.secrets.auth0_client_secret }
require 'base64'
# extracted from original [method](http://www.rubydoc.info/github/jwt/ruby-jwt/JWT.base64url_decode)
config.token_secret_signature_key = -> {
secret = Rails.application.secrets.auth0_client_secret
secret += '=' * (4 - secret.length.modulo(4))
Base64.decode64(secret.tr('-_', '+/'))
}
```

### 4. You're done!

Now you have both your FrontEnd and Backend configured to use Auth0. Congrats, you're awesome!

### Optional Steps
#### Configure CORS

In order to configure CORS, install [rack-cors](https://github.com/cyu/rack-cors) gem and follow [this](https://github.com/cyu/rack-cors#rails) instructions.
2 changes: 1 addition & 1 deletion snippets/server-apis/rails/dependencies.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```ruby
gem 'knock', '~> 1.2'
gem 'knock', '~> 1.4.2'
```
2 changes: 1 addition & 1 deletion snippets/server-apis/rails/setup.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```ruby
class ApplicationController < ActionController::API
class ApplicationController < ActionController::Base
include Knock::Authenticable
end
```

0 comments on commit bbe6420

Please sign in to comment.