question

Smit Shah avatar image
Smit Shah asked Smit Shah commented

C# SDK and RingCentral JWT

Hello Experts

Is there a basic working .Net sample on how to let a client authorize our app so we can get the access token and move forward from there?

We are able to get the token via password auth.

https://developers.ringcentral.com/guide/authentication/jwt-flow does not have sample payload necessary.

Your help is much appreciated.

authentication
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Phong Vu avatar image
Phong Vu answered Smit Shah commented

This is a public function in the .NET SDK

public Task<TokenInfo> Authorize(string jwt)
{
    var getTokenRequest = new GetTokenRequest
    {
        grant_type = "urn:ietf:params:oauth:grant-type:jwt-bearer",
        assertion = jwt
    };
    return Authorize(getTokenRequest);
}

So you can authenticate your app like this

...
static RestClient restClient;
static void Main(string[] args)
{
    restClient = new RestClient(
                "RC_CLIENT_ID, "RC_CLIENT_SECRET", "RC_SERVER_URL");
    restClient.Authorize("JWT_TOKEN").Wait();
    ...
}
9 comments
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Hey Phong

Thank you for your response.


The way I understand is that I would have page (aspx) that would have a button which will pass parameters to RC and RC will redirect back with the approval payload (json).


My experience with JWT authentication is very limited, so may be this might be a silly question. But what is the order of calls to be made? Also, which RingCentral library to use (there are two or three that I see on nuget).


Again, my apologies if these are too obvious of a question to be asking here.

0 Likes 0 ·

JWT tokens can be used to replace the password flow which requires a username and password. It is used for Server-only (No UI) application.

What you wrote made me doubt that you want a user to login the app from a Web page. If that is the case, you have to create a Browser app (instead of Server-only) and choose the 3-legged authorization flow. See this quick start to begin. It also shows you what nugget packages you need to add to your project.

0 Likes 0 ·
Smit Shah avatar image Smit Shah Phong Vu ♦♦ ·

I did review that tutorial earlier.

But that code does not even compile.

1649716148766.png


This is kind of where I am wondering what I am doing wrong and posted the question here.


0 Likes 0 ·
1649716148766.png (98.3 KiB)
Show more comments

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys