Skip to content

Commit

Permalink
Merge pull request #4 from shyTNT/BingAds/master
Browse files Browse the repository at this point in the history
Release .NET SDK 10.4.5
  • Loading branch information
shyTNT committed May 30, 2016
2 parents 0308a4d + c01d303 commit 5287785
Show file tree
Hide file tree
Showing 14 changed files with 465 additions and 46 deletions.
1 change: 1 addition & 0 deletions BingAdsApiSDK/BingAdsApiSDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@
<Compile Include="V10\Bulk\Entities\AdExtensions\BulkSiteLink.cs" />
<Compile Include="V10\Bulk\Entities\AdExtensions\BulkSiteLinkAdExtension.cs" />
<Compile Include="V10\Bulk\Entities\Ads\BulkProductAd.cs" />
<Compile Include="V10\Bulk\Entities\Ads\BulkAppInstallAd.cs" />
<Compile Include="V10\Bulk\Entities\Ads\BulkTextAd.cs" />
<Compile Include="V10\Bulk\Entities\BidSuggestionData.cs" />
<Compile Include="V10\Bulk\Entities\BulkAccount.cs" />
Expand Down
4 changes: 4 additions & 0 deletions BingAdsApiSDK/Internal/ErrorMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ internal static class ErrorMessages

public const string UriDoesntContainExpiresIn = "Uri passed doesn't contain expires_in param. Please make sure the has an expires_in param in it";

public const string UriDoesntContainState = "Uri passed doesn't contain state param while authentication requires a state verification. Please make sure the uri has a state in it, for example http://myurl.com?code=123&state=MyState";

public const string UriDoesntMatchState = "The state passed in Uri does not match the state value specified in authentication";

public const string UserDataAuthenticationIsNull = "UserData object has the Authentication property set to null. Please make sure it's not null before calling this method";
public const string UserDataDeveloperTokenIsNull = "UserData object has the DeveloperToken property set to null. Please make sure it's not null before calling this method";

Expand Down
2 changes: 1 addition & 1 deletion BingAdsApiSDK/Internal/OAuth/LiveComOAuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static Uri GetAuthorizationEndpoint(OAuthUrlParameters parameters)
"https://login.live.com/oauth20_authorize.srf?client_id={0}&scope=bingads.manage&response_type={1}&redirect_uri={2}",
parameters.ClientId,
parameters.ResponseType,
parameters.RedirectUri)
parameters.RedirectUri) + (string.IsNullOrEmpty(parameters.State) ? "": string.Format("&state={0}", parameters.State))
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions BingAdsApiSDK/Internal/OAuth/OAuthUrlParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ internal class OAuthUrlParameters
public string ResponseType { get; set; }

public Uri RedirectUri { get; set; }

public string State { get; set; }
}
}
44 changes: 43 additions & 1 deletion BingAdsApiSDK/Internal/OAuthWithAuthorizationCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public abstract class OAuthWithAuthorizationCode : OAuthAuthorization

private readonly IOAuthService _oauthService;

/// <summary>
/// An opaque value used by the client to maintain state between the request and callback.
/// </summary>
public string State { get; set; }

/// <summary>
/// Reserved for internal use.
/// </summary>
Expand Down Expand Up @@ -129,6 +134,42 @@ protected OAuthWithAuthorizationCode(string clientId, string optionalClientSecre
OAuthTokens = new OAuthTokens(null, 0, refreshToken);
}

/// <summary>
/// Initializes a new instance of the OAuthWebAuthCodeGrant class.
/// </summary>
/// <param name="clientId">
/// The client identifier corresponding to your registered application.
/// </param>
/// <param name="optionalClientSecret">
/// The client secret corresponding to your registered application, or null if your app is a desktop or mobile app.
/// </param>
/// <param name="redirectionUri">
/// The URI to which the user of the app will be redirected after receiving user consent.
/// </param>
/// <param name="oauthTokens">
/// Contains information about OAuth access tokens received from the Microsoft Account authorization service.
/// </param>
/// <remarks>
/// <para>
/// For more information about using a client identifier for authentication, see
/// <see href="http://tools.ietf.org/html/draft-ietf-oauth-v2-15#section-3.1">Client Password Authentication section of the OAuth 2.0 spec</see>.
/// </para>
/// <para>
/// For web applications, redirectionUri must be within the same domain of your registered application.
/// For more information, see <see href="http://tools.ietf.org/html/draft-ietf-oauth-v2-15#section-2.1.1">Redirection Uri section of the OAuth 2.0 spec</see>.
/// </para>
/// </remarks>
protected OAuthWithAuthorizationCode(string clientId, string optionalClientSecret, Uri redirectionUri, OAuthTokens oauthTokens)
: this(clientId, optionalClientSecret, redirectionUri, new LiveComOAuthService())
{
if (oauthTokens == null || oauthTokens.RefreshToken == null)
{
throw new ArgumentNullException("oAuthTokens");
}

OAuthTokens = new OAuthTokens(null, 0, oauthTokens.RefreshToken);
}

/// <summary>
/// Initializes a new instance of the OAuthWithAuthorizationCode class.
/// </summary>
Expand Down Expand Up @@ -179,7 +220,8 @@ public override Uri GetAuthorizationEndpoint()
{
ClientId = ClientId,
ResponseType = "code",
RedirectUri = RedirectionUri
RedirectUri = RedirectionUri,
State = State
});
}

Expand Down
18 changes: 18 additions & 0 deletions BingAdsApiSDK/OAuthDesktopMobileAuthCodeGrant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ public OAuthDesktopMobileAuthCodeGrant(string clientId, string refreshToken)

}

/// <summary>
/// Initializes a new instance of the OAuthDesktopMobileAuthCodeGrant class with the specified ClientId.
/// </summary>
/// <param name="clientId">
/// The client identifier corresponding to your registered application.
/// </param>
/// <param name="oauthTokens">
/// Contains information about OAuth access tokens received from the Microsoft Account authorization service.
/// </param>
/// <remarks>
/// For more information about using a client identifier for authentication, see <see href="http://tools.ietf.org/html/draft-ietf-oauth-v2-15#section-3.1">Client Password Authentication section of the OAuth 2.0 spec</see>.
/// </remarks>
public OAuthDesktopMobileAuthCodeGrant(string clientId, OAuthTokens oauthTokens)
: base(clientId, null, LiveComOAuthService.DesktopRedirectUri, oauthTokens)
{

}

internal OAuthDesktopMobileAuthCodeGrant(string clientId, IOAuthService oauthService)
: base(clientId, null, LiveComOAuthService.DesktopRedirectUri, oauthService)
{
Expand Down
32 changes: 28 additions & 4 deletions BingAdsApiSDK/OAuthDesktopMobileImplicitGrant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ namespace Microsoft.BingAds
/// </para>
/// </remarks>
public class OAuthDesktopMobileImplicitGrant : OAuthAuthorization
{
{
/// <summary>
/// An opaque value used by the client to maintain state between the request and callback.
/// </summary>
public string State { get; set; }

/// <summary>
/// The URI to which your client browser will be redirected after receiving user consent.
/// </summary>
Expand All @@ -94,7 +99,25 @@ public OAuthDesktopMobileImplicitGrant(string clientId)
: base(clientId)
{

}
}

/// <summary>
/// Initializes a new instance of the OAuthDesktopMobileImplicitGrant class.
/// </summary>
/// <param name="clientId">
/// The client identifier corresponding to your registered application.
/// </param>
/// <param name="oAuthTokens">
/// Contains information about OAuth access tokens received from the Microsoft Account authorization service.
/// </param>
/// /// <remarks>
/// For more information about using a client identifier for authentication, see <see href="http://tools.ietf.org/html/draft-ietf-oauth-v2-15#section-3.1">Client Password Authentication section of the OAuth 2.0 spec</see>.
/// </remarks>
public OAuthDesktopMobileImplicitGrant(string clientId, OAuthTokens oAuthTokens)
: base(clientId)
{
OAuthTokens = oAuthTokens;
}

/// <summary>
/// Gets the Microsoft Account authorization endpoint where the user should be navigated to give his or her consent.
Expand All @@ -106,7 +129,8 @@ public override Uri GetAuthorizationEndpoint()
{
ClientId = ClientId,
ResponseType = "token",
RedirectUri = LiveComOAuthService.DesktopRedirectUri
RedirectUri = LiveComOAuthService.DesktopRedirectUri,
State = State
});
}

Expand All @@ -129,7 +153,7 @@ public OAuthTokens ExtractAccessTokenFromUri(Uri redirectUri)

if (!fragmentParts.ContainsKey("expires_in"))
{
throw new InvalidOperationException(ErrorMessages.UriDoesntContainAccessToken);
throw new InvalidOperationException(ErrorMessages.UriDoesntContainExpiresIn);
}

return OAuthTokens = new OAuthTokens(fragmentParts["access_token"], int.Parse(fragmentParts["expires_in"]), null);
Expand Down
34 changes: 34 additions & 0 deletions BingAdsApiSDK/OAuthWebAuthCodeGrant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,40 @@ public OAuthWebAuthCodeGrant(string clientId, string clientSecret, Uri redirecti
}
}

/// <summary>
/// Initializes a new instance of the OAuthWebAuthCodeGrant class.
/// </summary>
/// <param name="clientId">
/// The client identifier corresponding to your registered application.
/// </param>
/// <param name="clientSecret">
/// The client secret corresponding to your registered application, or null if your app is a desktop or mobile app.
/// </param>
/// <param name="redirectionUri">
/// The URI to which the user of the app will be redirected after receiving user consent.
/// </param>
/// <param name="oAuthTokens">
/// Contains information about OAuth access tokens received from the Microsoft Account authorization service.
/// </param>
/// <remarks>
/// <para>
/// For more information about using a client identifier for authentication, see
/// <see href="http://tools.ietf.org/html/draft-ietf-oauth-v2-15#section-3.1">Client Password Authentication section of the OAuth 2.0 spec</see>.
/// </para>
/// <para>
/// For web applications, redirectionUri must be within the same domain of your registered application.
/// For more information, see <see href="http://tools.ietf.org/html/draft-ietf-oauth-v2-15#section-2.1.1">Redirection Uri section of the OAuth 2.0 spec</see>.
/// </para>
/// </remarks>
public OAuthWebAuthCodeGrant(string clientId, string clientSecret, Uri redirectionUri, OAuthTokens oAuthTokens)
: base(clientId, clientSecret, redirectionUri, oAuthTokens)
{
if (clientSecret == null)
{
throw new ArgumentNullException("clientSecret");
}
}

internal OAuthWebAuthCodeGrant(string clientId, string clientSecret, Uri redirectionUri, IOAuthService oauthService)
: base(clientId, clientSecret, redirectionUri, oauthService)
{
Expand Down

0 comments on commit 5287785

Please sign in to comment.