How to create a client key and secret for registering an application on my site and how to use OAuth to implement a provider

Hi, I have a rails application and I want to create an API for it. I have never worked on building an API so far. So please tell me where I should start creating the API from. I want to make it publicly available so that developers can create applications using my API. I have two questions in my head.

I tried to run the demo on here , but only the part is working, but I can not start the client part.

I ask you to study this material in detail. Thanks in advance...!

+6
source share
1 answer

Some time has passed since this question was asked, and there are many great resources that have been created since I summarize and link below.

Adding an OAuth 2 Provider Feature

The Warcraft driver allows you to implement the functionality of the OAuth provider and is well documented and in good condition. It integrates well with Devise , and there are sample applications to learn from.

On the client side (for integration testing, or if you want to provide the Ruby client for external developers), you can use OmniAuth , and Doorkeeper docs guide you through the process of creating a custom strategy .

You may not need OAuth?

Depending on what type of API you are building, you may find that OAuth is redundant. OAuth is useful in cases where you are a content provider, and the developer is a third party who wants to access information on behalf of the user, but without the need to know their password.

If your use case is simpler (for example, you can provide a secret token and key directly to the API user), then generating and checking access tokens may be enough. In this case, you create a key (using SecureRandom.urlsafe_base64 , or has_secure_token if you are on Rails 5) and save it. The API user provides this token for each authentication request, and you can regenerate the token if the original has ever been compromised.

More information about this here and here .

+3
source

Source: https://habr.com/ru/post/899676/


All Articles