forked from ringcentral/RingCentral.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuthorizeUriExtension.cs
37 lines (32 loc) · 1 KB
/
AuthorizeUriExtension.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Linq;
namespace RingCentral.Net.AuthorizeUri
{
public class AuthorizeUriExtension : SdkExtension
{
private RestClient rc;
public override void Install(RestClient rc)
{
this.rc = rc;
}
// todo: support PKCE
public string BuildUri(AuthorizeRequest authorizeRequest)
{
if (authorizeRequest.response_type == null)
{
authorizeRequest.response_type = "code";
}
if (authorizeRequest.client_id == null)
{
authorizeRequest.client_id = this.rc.clientId;
}
var uriBuilder = new UriBuilder(this.rc.server)
{
Path = "/restapi/oauth/authorize",
Query = string.Join("&",
Utils.GetPairs(authorizeRequest).Select(t => $"{t.name}={Uri.EscapeUriString(t.value.ToString())}"))
};
return uriBuilder.Uri.ToString();
}
}
}