示例#1
0
        /// <summary>
        /// Actually performs the request to the Token endpoint.
        /// </summary>
        /// <param name="appId">The app id of this client</param>
        /// <param name="appSecret">The app secret of this client</param>
        /// <param name="grantType">The OAuth grant type</param>
        /// <param name="tokenType">The OAuth token type</param>
        /// <param name="code">The authorization code or refresh token</param>
        /// <param name="redirectUri">The redirect uri used to get the authorization code</param>
        /// <returns></returns>
        private AccessTokenWrapper GetAccessToken(string appId, string appSecret, string grantType, string tokenType, string code, string redirectUri)
        {
            var client = new RestClient(Configuration.BaseUrl);

            var request = new RestRequest(TokenPath, Method.POST);

            string body = string.Format("grant_type={0}&{1}={2}", grantType, tokenType, code);

            if (redirectUri != null)
            {
                body += string.Format("&redirect_uri={0}", redirectUri);
            }

            request.AddHeader("Authorization", "Basic " + GetBasicAuthToken(appId, appSecret));
            request.AddParameter("application/x-www-form-urlencoded", body, ParameterType.RequestBody);
            request.RequestFormat = DataFormat.Json;

            try
            {
                AccessTokenWrapper tokenResponse = null;
                var response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    // OK
                    tokenResponse = JsonConvert.DeserializeObject <AccessTokenWrapper>(response.Content);
                }
                else
                {
                    // NOK
                    throw new InvalidOperationException("Token endpoint returned an invalid response");
                }

                return(tokenResponse);
            }
            catch (Exception error)
            {
                // Log
                throw new InvalidOperationException("Token endpoint resulted in an error: " + error.Message);
            }
        }
 public VideoResultList PlaylistContentGoogle(string playlistId, string nextPageToken, [FromBody] AccessTokenWrapper accessTokenWrapper)
 {
     return(youtubeAudioService.GetPlaylistContentGoogle(playlistId, nextPageToken, accessTokenWrapper.AccessToken));
 }
 public IList <YoutubePlaylistModel> GetMyPlaylists([FromBody] AccessTokenWrapper accessTokenWrapper)
 {
     return(youtubeAudioService.GetMyPlaylists(accessTokenWrapper.AccessToken));
 }
示例#4
0
 public TokenRefreshedEventArgs(AccessTokenWrapper refreshTokenWrapper)
 {
     TokenResponse = refreshTokenWrapper;
 }