Ejemplo n.º 1
0
        /// <summary>
        /// Use the authorization code parameter sent back to <see cref="TraktAuthentication.OAuthRedirectUri"/> to get a <see cref="TraktOAuthAccessToken"/>
        /// (stored in <see cref="TraktAuthentication.CurrentOAuthAccessToken"/>. Save the <see cref="TraktOAuthAccessToken"/> and restore it to
        /// <see cref="TraktAuthentication.CurrentOAuthAccessToken"/> during initialization.
        /// </summary>
        /// <param name="code">The authorization code returned from OAuth</param>
        /// <param name="clientId">Get this from your app settings</param>
        /// <param name="clientSecret">Get this from your app settings</param>
        /// <param name="redirectUri">The uri to which Trakt should redirect upon successful authentication. Refer to <see cref="TraktAuthentication.OAuthRedirectUri"/> for further details.</param>
        /// <param name="grantType">The requested grant type</param>
        /// <returns>See summary</returns>
        public async Task <TraktOAuthTokenResponse> GetOAuthTokenAsync(string code, string clientId, string clientSecret, string redirectUri, TraktOAuthTokenGrantType grantType)
        {
            TraktOAuthTokenRequestBody body = null;

            if (grantType == TraktOAuthTokenGrantType.AuthorizationCode)
            {
                body = new TraktOAuthTokenRequestBody
                {
                    Code         = code,
                    ClientId     = clientId,
                    ClientSecret = clientSecret,
                    RedirectUri  = redirectUri,
                    GrantType    = TraktEnumHelper.GetDescription(grantType)
                };
            }
            else
            {
                body = new TraktOAuthTokenRequestBody
                {
                    RefreshToken = code,
                    ClientId     = clientId,
                    ClientSecret = clientSecret,
                    RedirectUri  = redirectUri,
                    GrantType    = TraktEnumHelper.GetDescription(grantType)
                };
            }

            return(await SendAsync(new TraktOAuthTokenRequest(Client)
            {
                RequestBody = body
            }));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Use the authorization code parameter sent back to <see cref="TraktAuthentication.OAuthRedirectUri"/> to get a <see cref="TraktOAuthAccessToken"/>
 /// (stored in <see cref="TraktAuthentication.CurrentOAuthAccessToken"/>. Save the <see cref="TraktOAuthAccessToken"/> and restore it to
 /// <see cref="TraktAuthentication.CurrentOAuthAccessToken"/> during initialization.
 /// </summary>
 /// <param name="code">The authorization code returned from OAuth</param>
 /// <param name="clientId">Get this from your app settings</param>
 /// <param name="clientSecret">Get this from your app settings</param>
 /// <param name="redirectUri">The uri to which Trakt should redirect upon successful authentication. Refer to <see cref="TraktAuthentication.OAuthRedirectUri"/> for further details.</param>
 /// <param name="grantType">The requested grant type</param>
 /// <returns>See summary</returns>
 public async Task <TraktOAuthTokenResponse> GetOAuthTokenAsync(string code, string clientId, string clientSecret, string redirectUri, TraktOAuthTokenGrantType grantType)
 {
     return(await SendAsync(new TraktOAuthTokenRequest(Client) {
         RequestBody = new TraktOAuthTokenRequestBody {
             Code = code,
             ClientId = clientId,
             ClientSecret = clientSecret,
             RedirectUri = redirectUri,
             GrantType = TraktEnumHelper.GetDescription(grantType)
         }
     }));
 }