question

corey-tenney avatar image
corey-tenney asked ·

Using Code/Token Path for SSO in Windows Form Application

I have written a Windows Forms app in C#, and everything works great in the sandbox.  However after talking to RingCentral about SSO we apparently cannot just use the Token path to authenticate.  Now that I am digging into the Code/Token path it seems this is only for Web Applications.

1. Has anybody used the Code/Token path in a windows form?  If so... how?

2. Any other ideas for SSO to work without using Code/Token path?
topic-default
1 |1000 characters needed characters left characters exceeded

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

1 Answer

· Write an Answer
Tyler Liu avatar image
Tyler Liu answered ·
For "Code/Token" are you talking about the Authorization Code flow ?  https://devcommunity.ringcentral.com/ringcentraldev/topics/using-oauth-2-0-authorization-code-grant-...

For Windows form, you can embed a web browser widget and let user do authorization there. You can set redirectUri to localhost or whatever uri. Because you can access the address of the web browser widget to get the auth code no matter what is the redirectUri.
10 comments Share
1 |1000 characters needed characters left characters exceeded

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

Tyler yes thats the code flow.  Its been about 20+ years since I did any Windows Forms stuff... so I really appreciate the information.
0 Likes 0 · ·
Tyler, can I use the RingCentral Nuget Package to do Code flow?  I didnt see a way to do it.
0 Likes 0 · ·
Yes, here is sample code:  https://github.com/ringcentral/ringcentral-demos-oauth/tree/master/csharp-nancy/csharp-client-nancy

Note: the sample code is using Nancy as local http sever to interpret the redirect uri. You don't need a local http server because you can access the web browser widget's address bar to get the redirect url directly.
0 Likes 0 · ·
I dont suppose you have the config.json?? its not in the github
0 Likes 0 · ·
Tyler, I found one for the SDK.. not the Client... are they the same?
0 Likes 0 · ·
You should use this one  https://github.com/ringcentral/ringcentral-csharp-client. Others are either deprecated or unofficial.
0 Likes 0 · ·
The demo code is this folder:  https://github.com/ringcentral/ringcentral-demos-oauth/tree/master/csharp-nancy/csharp-client-nancy

I don't think you can use it directly because the env is quite different. (website vs winform). For the config.json, it's just a json file with credentials. The fields can be found here:  https://github.com/ringcentral/ringcentral-demos-oauth/blob/master/csharp-nancy/csharp-client-nancy/...

I recommend you to take a look at: https://github.com/tylerlong/ringcentral-python#authorization-code-flow-3-legged-authorization-flow It describes the four steps of the oauth flow. It's in Python but the the flow is the same for C#.

If you cannot make it work. Please provide detailed error message or where you are stuck. I will be happy to help.
0 Likes 0 · ·
Tyler, so I have a webbrowser control, I got it to go out and able to login... however the login wants to come back to the redirectUri, which unless we setup a whole website just to get this back..... I really dont see a way within the webbrowser control to handle the return.
0 Likes 0 · ·
Corey, I don't remember the details. But you are the creator of the webbrowser control so you can access all of it properties including its URL.

Check this:  https://stackoverflow.com/questions/4913243/c-sharp-when-can-i-know-that-webbrowser-controller-url-c...  And this  https://stackoverflow.com/questions/9924382/how-to-get-the-url-of-a-webbrowser-control

You don't need to setup a whole website because the redirect uri is not important. You can set it to http://does-not-exist.com/oauth  and you just monitor the webbrowser url change. Whenever it changes to something like   http://does-not-exist.com/oauth ?code=xxxxx   Then you can get the code.
0 Likes 0 · ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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