Git Product home page Git Product logo

rd.net's Introduction

RD.NET

Real-Debrid .NET wrapper library written in C#

Supports all API calls and OAuth2 authentication.

Usage

Create an instance of RdNetClient for each user you want to authenticate. If you need to support multiple users you will need to create a new instance every time you switch users.

var client = new RdNetClient();

When no parameters are given in the constructor the default app ID is used for open source application.

The client follows the documentation closely in naming and parameters:

var client = new RdNetClient();
client.UseApiAuthentication("myapikey");

// See https://api.real-debrid.com/
await client.Unrestrict.CheckAsync("https://www.4shared.com/mp3/BilLPtwmea/file_example_MP3_5MG.html");

Authentication

Api Token

Call the UseApiAuthentication function with the API key for the user:

client.UseApiAuthentication("user API key");

Each user has its own API key, which can be found here: https://real-debrid.com/apitoken.

OAuth2 for open source applications

Workflow for opensource apps

This method does not require a client_id or client_secret and can be used in open source applications.

Call the following function to setup OAuth2:

client.UseOAuthAuthentication();

To authenticate the user call:

var result = await client.Authentication.GetDeviceAuthorizeRequestAsync();

This will give you a URL and code to have the user verify their device.

You can poll the result by doing:

var result = await client.Authentication.VerifyDeviceAuthentication();

If the result is NULL the user has not authorized the device. When the user has done so a response will be given with the ClientId and ClientSecret.

These tokens are now used to trade them in for authentication tokens:

var result = await client.Authentication.GetOAuthAuthorizationTokensAsync("ClientId", "ClientSecret");

The ClientId, ClientSecret, AccessToken and RefreshToken should be safely stored and are needed for future authentication.

To initialize the client again later with the tokens simply pass them to the UseOAuthAuthentication method:

client.UseOAuthAuthentication("user client_id", "user client_secret", "user access token", "user refresh token");

OAuth2 for closed source applications

Workflow for opensource apps

This method is the same as above except instead of passing in the user client_id and user client_secret you pass in your own client_id and client_secret.

Three legged OAuth2 for websites

Workflow for websites or client applications

Start the process by calling the GetOAuthAuthorizationUrl method to retrieve a URL to pass to the user:

var result = client.Authentication.GetOAuthAuthorizationUrl(new Uri("https://mywebsite"), "34f98j");

Navigate the user to the resulting URL, when the user accepts, the user will be redirected to the given reirect URL with 2 query parameters: code and state.

Use the state parameter to verify if the request is legit.

Use the code parameter to get the authentication tokens for the user:

var result = await client.Authentication.GetOAuthAuthorizationTokensAsync("Your clientId", "Your clientSecret", "Code");

The result will give you the AccessToken and RefreshToken.

To initialize the client with the tokens simply pass them to the UseOAuthAuthentication method:

client.UseOAuthAuthentication("your client_id", "your client_secret", "user access token", "user refresh token");

Refreshing the access token

When the access token is expired you will retrieve an AccessTokenExpired exception. Use the refresh token to renew the access token and store the access token:

var newCredentials = await client.Authentication.RefreshTokenAsync();

All tokens are cached in the client when refreshing, but it's your responsibility to retry the request with the new access token.

Unit tests

The unit tests are not designed to be ran all at once, they are used to act as a test client.

Create a file setup.txt and put your API token in there.

Some functions will need replacement ID's to work properly.

rd.net's People

Contributors

rogerfar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rd.net's Issues

Write the damn docs

#1

As pointed out: Docs insufficient and NOT present. The readme it's a joke of readme

Getting Available Files Method

Hello,

I am trying to use the torrents.GetAvailableFiles method and looking at the RD api documentation I am meant to pass in the info hash of a torrent. I am extracting this from a magnet link and passing it though as the Id parameter but I keep getting a RDNET.RealDebridException: Unknown method error

I have managed to authenticate before calling the method and I have a bearer token when making a request so I think that bit is alright

Can you assist in what I am doing wrong/missing?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.