-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from viagogo/auth_code_grant
Added IOAuth2Client methods for the Authorization Code grant type
- Loading branch information
Showing
12 changed files
with
279 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,80 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using GogoKit.Models.Response; | ||
using System; | ||
|
||
namespace GogoKit.Clients | ||
{ | ||
/// <summary> | ||
/// Provides methods used in OAuth authentication. | ||
/// </summary> | ||
/// <remarks>See http://developer.viagogo.net/#authentication</remarks> | ||
public interface IOAuth2Client | ||
{ | ||
/// <summary> | ||
/// Gets the URL where applications can obtain a user’s consent to make API calls | ||
/// on their behalf. | ||
/// </summary> | ||
/// <param name="redirectUri">Application return URL where the authorization code | ||
/// is sent. This must match the URL registered for your application</param> | ||
/// <param name="scopes">The scopes that specify the type of access that | ||
/// is needed.</param> | ||
/// <remarks> | ||
/// If the user accepts the request, viagogo will redirect them back to your | ||
/// application's <paramref name="redirectUrl"/> with a temporary code that | ||
/// can be exchanged for an access token. | ||
/// </remarks> | ||
Uri GetAuthorizationUrl(Uri redirectUri, IEnumerable<string> scopes); | ||
|
||
/// <summary> | ||
/// Gets the URL where applications can obtain a user’s consent to make API calls | ||
/// on their behalf. | ||
/// </summary> | ||
/// <param name="redirectUri">Application return URL where the authorization code | ||
/// is sent. This must match the URL registered for your application</param> | ||
/// <param name="scopes">The scopes that specify the type of access that | ||
/// is needed.</param> | ||
/// <param name="state">An opaque value used to maintain state between the | ||
/// authorize request and the callback.</param> | ||
/// <remarks> | ||
/// If the user accepts the request, viagogo will redirect them back to your | ||
/// application's <paramref name="redirectUrl"/> with a temporary code that | ||
/// can be exchanged for an access token. | ||
/// </remarks> | ||
Uri GetAuthorizationUrl(Uri redirectUri, IEnumerable<string> scopes, string state); | ||
|
||
/// <summary> | ||
/// Requests an OAuth access token. | ||
/// </summary> | ||
/// <param name="grantType">The OAuth2 grant type that should be used.</param> | ||
/// <param name="scopes">The scopes that specify the type of access that | ||
/// is needed.</param> | ||
/// <param name="parameters">Other parameters that should be sent in the | ||
/// request.</param> | ||
Task<OAuth2Token> GetAccessTokenAsync(string grantType, | ||
IEnumerable<string> scopes, | ||
IDictionary<string, string> parameters); | ||
|
||
/// <summary> | ||
/// Requests an access token that will provide access to user-specific | ||
/// data (purchases, sales, listings, etc). | ||
/// </summary> | ||
/// <param name="code">The authorization code that was sent to your | ||
/// application’s return URL.</param> | ||
/// <param name="scopes">The scopes that specify the type of access that | ||
/// is needed.</param> | ||
Task<OAuth2Token> GetAuthorizationCodeAccessTokenAsync(string code, IEnumerable<string> scopes); | ||
|
||
/// <summary> | ||
/// Requests an access token that will provide access to public, non-user-specific | ||
/// data (events, listings, etc). | ||
/// </summary> | ||
Task<OAuth2Token> GetClientAccessTokenAsync(IEnumerable<string> scopes); | ||
|
||
/// <summary> | ||
/// Obtain additional access tokens in order to prolong access to a | ||
/// user’s data. | ||
/// </summary> | ||
Task<OAuth2Token> RefreshAccessTokenAsync(OAuth2Token token); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using GogoKit.Enumerations; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace GogoKit | ||
{ | ||
public static class Default | ||
{ | ||
public static readonly IDictionary<ApiEnvironment, Uri> ViagogoApiRootEndpoints = | ||
new Dictionary<ApiEnvironment, Uri>() | ||
{ | ||
[ApiEnvironment.Production] = new Uri("https://api.viagogo.net/v2"), | ||
[ApiEnvironment.Sandbox] = new Uri("https://sandbox.api.viagogo.net/v2") | ||
}; | ||
|
||
public static readonly IDictionary<ApiEnvironment, Uri> ViagogoOAuthTokenEndpoints = | ||
new Dictionary<ApiEnvironment, Uri>() | ||
{ | ||
[ApiEnvironment.Production] = new Uri("https://account.viagogo.com/oauth2/token"), | ||
[ApiEnvironment.Sandbox] = new Uri("https://sandbox.account.viagogo.com/oauth2/token") | ||
}; | ||
|
||
public static readonly IDictionary<ApiEnvironment, Uri> ViagogoAuthorizationEndpoints = | ||
new Dictionary<ApiEnvironment, Uri>() | ||
{ | ||
[ApiEnvironment.Production] = new Uri("https://account.viagogo.com/authorize"), | ||
[ApiEnvironment.Sandbox] = new Uri("https://sandbox.account.viagogo.com/authorize") | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace GogoKit.Enumerations | ||
{ | ||
public enum ApiEnvironment | ||
{ | ||
Production, | ||
Sandbox | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,97 @@ | ||
using System; | ||
using GogoKit.Enumerations; | ||
using HalKit; | ||
using System.Threading; | ||
|
||
namespace GogoKit | ||
{ | ||
public class GogoKitConfiguration : IGogoKitConfiguration | ||
{ | ||
public static readonly Uri DefaultViagogoApiRootEndpoint = new Uri("https://api.viagogo.net/v2"); | ||
public static readonly Uri DefaultViagogoOAuthTokenEndpoint = new Uri("https://www.viagogo.com/secure/oauth2/token"); | ||
|
||
private readonly HalKitConfiguration _halKitConfiguration; | ||
private ApiEnvironment _apiEnvironment; | ||
|
||
public GogoKitConfiguration() | ||
{ | ||
_halKitConfiguration = new HalKitConfiguration(DefaultViagogoApiRootEndpoint) | ||
_halKitConfiguration = new HalKitConfiguration(Default.ViagogoApiRootEndpoints[ApiEnvironment.Production]) | ||
{ | ||
CaptureSynchronizationContext = false | ||
}; | ||
ViagogoOAuthTokenEndpoint = DefaultViagogoOAuthTokenEndpoint; | ||
ViagogoApiEnvironment = ApiEnvironment.Production; | ||
} | ||
|
||
/// <summary> | ||
/// The root endpoint of the API to get the root resource that links to | ||
/// all other API resources. | ||
/// </summary> | ||
/// <remarks>See http://developer.viagogo.net/#explorable-api</remarks> | ||
public Uri ViagogoApiRootEndpoint | ||
{ | ||
get { return _halKitConfiguration.RootEndpoint; } | ||
set { _halKitConfiguration.RootEndpoint = value; } | ||
} | ||
|
||
/// <summary> | ||
/// The endpoint where OAuth2 access tokens are granted. | ||
/// </summary> | ||
/// <remarks>See http://developer.viagogo.net/#getting-access-tokens</remarks> | ||
public Uri ViagogoOAuthTokenEndpoint { get; set; } | ||
|
||
/// <summary> | ||
/// The endpoint where applications can obtain a user’s consent to make API calls | ||
/// on their behalf. | ||
/// </summary> | ||
/// <remarks>See http://developer.viagogo.net/#authorization-code-grant</remarks> | ||
public Uri ViagogoAuthorizationEndpoint { get; set; } | ||
|
||
/// <summary> | ||
/// Determines which <see cref="ApiEnvironment"/> should be used. Setting | ||
/// this value will configure the values for <see cref="ViagogoApiRootEndpoint"/>, | ||
/// <see cref="ViagogoOAuthTokenEndpoint"/> and <see cref="ViagogoAuthorizationEndpoint"/>. | ||
/// </summary> | ||
/// <remarks>See http://developer.viagogo.net/#sandbox-environment</remarks> | ||
public ApiEnvironment ViagogoApiEnvironment | ||
{ | ||
get | ||
{ | ||
return _apiEnvironment; | ||
} | ||
set | ||
{ | ||
_apiEnvironment = value; | ||
ViagogoApiRootEndpoint = Default.ViagogoApiRootEndpoints[_apiEnvironment]; | ||
ViagogoOAuthTokenEndpoint = Default.ViagogoOAuthTokenEndpoints[_apiEnvironment]; | ||
ViagogoAuthorizationEndpoint = Default.ViagogoAuthorizationEndpoints[_apiEnvironment]; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Determines whether asynchronous operations should capture the current | ||
/// <see cref="SynchronizationContext"/>. | ||
/// </summary> | ||
/// <remarks>See http://blog.stephencleary.com/2012/02/async-and-await.html#avoiding-context.</remarks> | ||
public bool CaptureSynchronizationContext | ||
{ | ||
get { return _halKitConfiguration.CaptureSynchronizationContext; } | ||
set { _halKitConfiguration.CaptureSynchronizationContext = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Determines the language of the API response content (e.g. event names | ||
/// and error messages). | ||
/// </summary> | ||
/// <remarks>See http://developer.viagogo.net/#localization</remarks> | ||
public string LanguageCode { get; set; } | ||
|
||
/// <summary> | ||
/// Determines the geography-context of requests. | ||
/// </summary> | ||
/// <remarks>See http://developer.viagogo.net/#localization</remarks> | ||
public string CountryCode { get; set; } | ||
|
||
/// <summary> | ||
/// Determines the currency of responses that include monetary values. | ||
/// </summary> | ||
/// <remarks>See http://developer.viagogo.net/#localization</remarks> | ||
public string CurrencyCode { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.