Ejemplo n.º 1
0
        /// <summary>
        ///     Method to generate Access Token and Refresh Token by authorization code grant type
        /// </summary>
        /// <param name="authCodeParams">Parameters of requesting authorization code</param>
        /// <returns>string response of Authenticate result.</returns>
        public Response AuthorizeByAuthCode(string grant_type, string code, string redirect_uri)
        {
            var body = new Dictionary <string, string>()
            {
                { "grant_type", grant_type },
                { "code", code },
                { "redirect_uri", redirect_uri },
                { "access_token_ttl", AccessTokenTtl },
                { "refresh_token_ttl", RefreshTokenTtl }
            };

            var request = new Request(TokenEndpoint, body);
            var result  = AuthCall(request);

            Auth.SetData(result.GetJson());

            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Auth.GetAccessToken());

            return(result);
        }
Ejemplo n.º 2
0
        /// <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);
        }