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

Doorkeeper integration. #133

Merged
merged 1 commit into from
Sep 30, 2015
Merged

Doorkeeper integration. #133

merged 1 commit into from
Sep 30, 2015

Conversation

raulanatol
Copy link
Contributor

Hi!

I created a integration with doorkeeper and camaleon-cms (oauth integration).
I added a basic api structure also.

Regards

owen2345 added a commit that referenced this pull request Sep 30, 2015
@owen2345 owen2345 merged commit 237cc6b into owen2345:master Sep 30, 2015
@owen2345
Copy link
Owner

Raul, can you write a small doc to use this?

@raulanatol raulanatol deleted the api_oauth branch September 30, 2015 13:56
@raulanatol
Copy link
Contributor Author

Hi @owen2345.

This is a small checklist.

bundle update
rake db:migrate
rails s

Go to http://localhost:3000/oauth/applications and create a new application.
Important use this scopes: public admin client

And now using the Application Id and Secret make an api connection.
At the end of comment I attached a simple javascript sample.

The most important code:

      var appUID = '62fdacddce1b60a7151f3718b6dc8b31a26ee6369a8c814ebdda0dece6a1b304';
      var secret = 'cfbb47b6950347004a1d8c8c2e4bd2c338d22dfd25bff223f043081dd43672fd';

      function getCategories(token) {
        $.ajax({
          url: 'http://localhost:3000/api/v1/categories',
          headers: {
            'Authorization': 'Bearer ' + token
          }
        }).success(function(response){
          console.log(response);
        })
      }

      function login() {
        var data = 'username=' + 'admin' + '&password=' + 'admin' + '&grant_type=password&scope=public%20admin%20client';
        $.post('http://localhost:3000/oauth/token', data, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': 'application/json',
            'Authorization': 'Basic ' + $.base64.encode(appUID + ':' + secret)
          }
        }).success(function(response){
          console.log('New token: ' + response.access_token);
          getCategories(response.access_token);
        });
      }

If you have any problem with cors I usually use https://github.com/cyu/rack-cors

I hope it's enough.

Regards.


index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Rest client</title>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="libs/jquery.base64.min.js"></script
  </head>

  <body>
    <a href="javascript:login()">login</a>

    <script type="text/javascript">
      var appUID = '62fdacddce1b60a7151f3718b6dc8b31a26ee6369a8c814ebdda0dece6a1b304';
      var secret = 'cfbb47b6950347004a1d8c8c2e4bd2c338d22dfd25bff223f043081dd43672fd';

      function getCategories(token) {
        $.ajax({
          url: 'http://localhost:3000/api/v1/categories',
          headers: {
            'Authorization': 'Bearer ' + token
          }
        }).success(function(response){
          console.log(response);
        })
      }

      function login() {
        var data = 'username=' + 'admin' + '&password=' + 'admin' + '&grant_type=password&scope=public%20admin%20client';
        $.post('http://localhost:3000/oauth/token', data, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': 'application/json',
            'Authorization': 'Basic ' + $.base64.encode(appUID + ':' + secret)
          }
        }).success(function(response){
          console.log('New token: ' + response.access_token);
          getCategories(response.access_token);
        });
      }

    </script>
  </body>
</html>

jquery-base64: http://github.com/carlo/jquery-base64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants