Hihi! I'm trying to use JWT Authentication in what I think should be a simple C# script, but I'm having trouble getting my JWT to authorize and was hoping some of y'all lovely ppl might be able to help.
DISCLAIMER: I'm totally new to the RingCentral API (and fairly new to programming in general), so please excuse any incorrect terminology and feel free to correct me on anything!
I've (I think) set up my Visual Studio project correctly as described in RC's JWT Auth documentation here, but for some reason, when I try to authorize the JWT, Visual Studio throws me an error at line 17, telling me it "cannot convert from 'string' to 'RingCentral.GetTokenRequest", and of course then refuses to compile.
I'm struggling to understand why this is happening, though, being that it's verbatim RC's example code, unless I did something wrong setting up the project? I don't know enough about the "GetTokenRequest" type to properly diagnose this, but I don't see how I could define the JWT as anything other than a string since it's just text.
Again, I'm still very new to programming, so it's entirely possible I'm just missing something super obvious.
I've included the code I'm working with (ripped directly from the link above).
Any help would be greatly appreciated!!!!
Current C# Script:
using System;
using System.Threading.Tasks;
using RingCentral;
namespace JWT_Auth
{
class Program
{
static RestClient restClient;
static void Main(string[] args)
{
restClient = new RestClient(
Environment.GetEnvironmentVariable("RC_CLIENT_ID"),
Environment.GetEnvironmentVariable("RC_CLIENT_SECRET"),
Environment.GetEnvironmentVariable("RC_SERVER_URL"));
restClient.Authorize(
Environment.GetEnvironmentVariable("RC_JWT")).Wait();
Console.WriteLine("Successfully authed.");
}
}
}
Current .env file:
# Sandbox #RC_SERVER_URL = 'https://platform.devtest.ringcentral.com' # Production RC_SERVER_URL = 'https://platform.ringcentral.com' RC_CLIENT_ID = 'MY_CLIENT_ID' RC_CLIENT_SECRET = 'MY_CLIENT_SECRET' # This credential is used for JWT-grant types RC_JWT = 'MY_JWT'
Again, any help or advice is welcome!!
Can you change your code like this
// I don't know how you load the .env file. But you should have this in your project using dotenv.net; namespace JWT_Auth { class Program { static RestClient restClient; static void Main(string[] args) { DotEnv.Load(); restClient = new RestClient( Environment.GetEnvironmentVariable("RC_CLIENT_ID"), Environment.GetEnvironmentVariable("RC_CLIENT_SECRET"), Environment.GetEnvironmentVariable("RC_SERVER_URL")); await restClient.Authorize(Environment.GetEnvironmentVariable("RC_JWT" Console.WriteLine("Successfully authed."); } } }
Better see the entire sample code here
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