/// <summary> /// Method to generate Access Token and Refresh Token to establish an authenticated session /// </summary> /// <param name="userName">Login of RingCentral user</param> /// <param name="password">Password of the RingCentral User</param> /// <param name="extension">Optional: Extension number to login</param> /// <param name="isRemember">If set to true, refresh token TTL will be one week, otherwise it's 10 hours</param> /// <returns>string response of Authenticate result.</returns> public Response Authorize(string userName, string extension, string password, bool isRemember) { var body = new Dictionary <string, string> { { "username", userName }, { "password", Uri.EscapeUriString(password) }, { "extension", extension }, { "grant_type", "password" }, { "access_token_ttl", AccessTokenTtl }, { "refresh_token_ttl", isRemember ? RefreshTokenTtlRemember : RefreshTokenTtl } }; var request = new Request(TokenEndpoint, body); var result = AuthCall(request); Auth.SetRemember(isRemember); Auth.SetData(result.GetJson()); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Auth.GetAccessToken()); return(result); }
/// <summary> /// Generates a OAuth 2.0 URL for the authorization code grant type /// </summary> /// <param name="authCodeParams">Parameters of requesting authCode</param> public string CreateUrl(string path, Options options) { path = path ?? string.Empty; options = options ?? new Options(); StringBuilder builtUrl = new StringBuilder(); bool hasHttp = path.StartsWith("http://") || path.Contains("https://"); if (options.addServer && !hasHttp) { builtUrl.Append(ApiEndpoint); } if (!path.Contains(UrlPrefix) && !hasHttp) { builtUrl.Append(UrlPrefix).Append("/").Append(ApiVersion); } builtUrl.Append(path); if (!string.IsNullOrEmpty(options.addMethod) || options.addToken) { builtUrl.Append(UrlPrefix.Contains("?")?"&":"?"); } if (!string.IsNullOrEmpty(options.addMethod)) { builtUrl.Append("_method=").Append(options.addMethod); } if (options.addToken) { builtUrl.Append(!string.IsNullOrEmpty(options.addMethod) ? "&" : "").Append("access_token=").Append(Auth.GetAccessToken()); } return(builtUrl.ToString()); }