News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
C# SDK and RingCentral JWT
Tags: authentication
Apr 10, 2022 at 9:52pm   •   1 replies  •  0 likes
Smit Shah

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.

1 Answer
answered on Apr 11, 2022 at 9:36am  

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();
    ...
}

 0
on Apr 11, 2022 at 11:53am   •  0 likes

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.

on Apr 11, 2022 at 12:36pm   •  0 likes

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.

on Apr 11, 2022 at 3:30pm   •  0 likes

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.


on Apr 11, 2022 at 8:33pm   •  0 likes

Hi @Smit Shah
I have attached an example of OAuth using the SDK as part of the email chain we have had.
I am adding it here again for your reference https://github.com/nerdchacha/dotnet-oauth-demo

on Apr 11, 2022 at 9:27pm   •  0 likes

Thanks Tyler and Yatin, that extension piece is what I was missing.

Made some good progress based on your feedback, thank you.

So as a follow up question, where can I find info on

1) If the token I get is going to let me pull call logs for "all users" if super admin authorizes, or if I will have to authorize each user in the client's account?

2) Is there a tutorial on how to track token expiration and handle token refresh?


Please let me know if you'd prefer I open a new topic for these questions.

Thank you both again so much for your help.

on Apr 11, 2022 at 10:35pm   •  0 likes

@Smit Shah

1. You can use the readCompanyCallLog endpoint to read call logs of the entire account
https://developers.ringcentral.com/api-reference/Call-Log/readCompanyCallLog
You need to make sure your application has the "ReadCallLog" permission and the user you are using to log in to the app to get the access token has the "ReadAccountCallLog" permission.
Your super admin should have the "ReadAccountCallLog" permission

These details can be found here for every API endpoint
screenshot-2022-04-12-at-110253-am.png


2. You can find the guide on handling and refreshing token herehttps://developers.ringcentral.com/guide/authentication/refresh-tokens

on Apr 13, 2022 at 10:22pm   •  0 likes

So, when I look at https://developers.ringcentral.com/guide/authentication/refresh-tokens I am not sure how/which value for refresh_token do I use.


I am now able to successfully use OAuth and get the first set of tokens, no problem.

on Apr 14, 2022 at 8:42am   •  1 likes

Nevermind, found it under platform.refresh

on Apr 11, 2022 at 5:00pm   •  0 likes

The authorizeUri method has been moved to an extension since RingCentral.Net 5.0: https://github.com/ringcentral/RingCentral.Net/tree/master/RingCentral.Net.AuthorizeUri

Then guide hasn't been updated.



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us