Google Api
This commit is contained in:
parent
e307811d89
commit
83f9fc1bd8
123 changed files with 12961 additions and 60 deletions
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
Copyright 2013 Google Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
using Google.Apis.Requests;
|
||||
using Google.Apis.Requests.Parameters;
|
||||
|
||||
namespace Google.Apis.Auth.OAuth2.Requests
|
||||
{
|
||||
/// <summary>
|
||||
/// OAuth 2.0 request URL for an authorization web page to allow the end user to authorize the application to
|
||||
/// access their protected resources and that returns an authorization code, as specified in
|
||||
/// http://tools.ietf.org/html/rfc6749#section-4.1.
|
||||
/// </summary>
|
||||
public class AuthorizationCodeRequestUrl : AuthorizationRequestUrl
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs a new authorization code request with the specified URI and sets response_type to <c>code</c>.
|
||||
/// </summary>
|
||||
public AuthorizationCodeRequestUrl(Uri authorizationServerUrl)
|
||||
: base(authorizationServerUrl)
|
||||
{
|
||||
ResponseType = "code";
|
||||
}
|
||||
|
||||
/// <summary>Creates a <see cref="System.Uri"/> which is used to request the authorization code.</summary>
|
||||
public Uri Build()
|
||||
{
|
||||
var builder = new RequestBuilder()
|
||||
{
|
||||
BaseUri = AuthorizationServerUrl
|
||||
};
|
||||
ParameterUtils.InitParameters(builder, this);
|
||||
return builder.BuildUri();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
Copyright 2013 Google Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Google.Apis.Auth.OAuth2.Requests
|
||||
{
|
||||
/// <summary>
|
||||
/// OAuth 2.0 request for an access token using an authorization code as specified in
|
||||
/// http://tools.ietf.org/html/rfc6749#section-4.1.3.
|
||||
/// </summary>
|
||||
public class AuthorizationCodeTokenRequest : TokenRequest
|
||||
{
|
||||
/// <summary>Gets or sets the authorization code received from the authorization server.</summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("code")]
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the redirect URI parameter matching the redirect URI parameter in the authorization request.
|
||||
/// </summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("redirect_uri")]
|
||||
public string RedirectUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new authorization code token request and sets grant_type to <c>authorization_code</c>.
|
||||
/// </summary>
|
||||
public AuthorizationCodeTokenRequest()
|
||||
{
|
||||
GrantType = "authorization_code";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
Copyright 2013 Google Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Google.Apis.Auth.OAuth2.Requests
|
||||
{
|
||||
/// <summary>
|
||||
/// OAuth 2.0 request URL for an authorization web page to allow the end user to authorize the application to
|
||||
/// access their protected resources, as specified in http://tools.ietf.org/html/rfc6749#section-3.1.
|
||||
/// </summary>
|
||||
public class AuthorizationRequestUrl
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the response type which must be <c>code</c> for requesting an authorization code or
|
||||
/// <c>token</c> for requesting an access token (implicit grant), or space separated registered extension
|
||||
/// values. See http://tools.ietf.org/html/rfc6749#section-3.1.1 for more details
|
||||
/// </summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("response_type", Google.Apis.Util.RequestParameterType.Query)]
|
||||
public string ResponseType { get; set; }
|
||||
|
||||
/// <summary>Gets or sets the client identifier.</summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("client_id", Google.Apis.Util.RequestParameterType.Query)]
|
||||
public string ClientId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the URI that the authorization server directs the resource owner's user-agent back to the
|
||||
/// client after a successful authorization grant, as specified in
|
||||
/// http://tools.ietf.org/html/rfc6749#section-3.1.2 or <c>null</c> for none.
|
||||
/// </summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("redirect_uri", Google.Apis.Util.RequestParameterType.Query)]
|
||||
public string RedirectUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets space-separated list of scopes, as specified in http://tools.ietf.org/html/rfc6749#section-3.3
|
||||
/// or <c>null</c> for none.
|
||||
/// </summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("scope", Google.Apis.Util.RequestParameterType.Query)]
|
||||
public string Scope { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the state (an opaque value used by the client to maintain state between the request and
|
||||
/// callback, as mentioned in http://tools.ietf.org/html/rfc6749#section-3.1.2.2 or <c>null</c> for none.
|
||||
/// </summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("state", Google.Apis.Util.RequestParameterType.Query)]
|
||||
public string State { get; set; }
|
||||
|
||||
private readonly Uri authorizationServerUrl;
|
||||
/// <summary>Gets the authorization server URI.</summary>
|
||||
public Uri AuthorizationServerUrl
|
||||
{
|
||||
get { return authorizationServerUrl; }
|
||||
}
|
||||
|
||||
/// <summary>Constructs a new authorization request with the specified URI.</summary>
|
||||
/// <param name="authorizationServerUrl">Authorization server URI</param>
|
||||
public AuthorizationRequestUrl(Uri authorizationServerUrl)
|
||||
{
|
||||
this.authorizationServerUrl = authorizationServerUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
Copyright 2013 Google Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
namespace Google.Apis.Auth.OAuth2.Requests
|
||||
{
|
||||
/// <summary>
|
||||
/// Service account assertion token request as specified in
|
||||
/// https://developers.google.com/accounts/docs/OAuth2ServiceAccount#makingrequest.
|
||||
/// </summary>
|
||||
public class GoogleAssertionTokenRequest : TokenRequest
|
||||
{
|
||||
/// <summary>Gets or sets the JWT (including signature).</summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("assertion")]
|
||||
public string Assertion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new refresh code token request and sets grant_type to
|
||||
/// <c>urn:ietf:params:oauth:grant-type:jwt-bearer</c>.
|
||||
/// </summary>
|
||||
public GoogleAssertionTokenRequest()
|
||||
{
|
||||
GrantType = "urn:ietf:params:oauth:grant-type:jwt-bearer";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
Copyright 2013 Google Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Google.Apis.Auth.OAuth2.Requests
|
||||
{
|
||||
/// <summary>
|
||||
/// Google-specific implementation of the OAuth 2.0 URL for an authorization web page to allow the end user to
|
||||
/// authorize the application to access their protected resources and that returns an authorization code, as
|
||||
/// specified in https://developers.google.com/accounts/docs/OAuth2WebServer.
|
||||
/// </summary>
|
||||
public class GoogleAuthorizationCodeRequestUrl : AuthorizationCodeRequestUrl
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the access type. Set <c>online</c> to request on-line access or <c>offline</c> to request
|
||||
/// off-line access or <c>null</c> for the default behavior. The default value is <c>offline</c>.
|
||||
/// </summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("access_type", Google.Apis.Util.RequestParameterType.Query)]
|
||||
public string AccessType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets prompt for consent behavior <c>auto</c> to request auto-approval or<c>force</c> to force the
|
||||
/// approval UI to show, or <c>null</c> for the default behavior.
|
||||
/// </summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("approval_prompt", Google.Apis.Util.RequestParameterType.Query)]
|
||||
public string ApprovalPrompt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the login hint. Sets <c>email address</c> or sub <c>identifier</c>.
|
||||
/// When your application knows which user it is trying to authenticate, it may provide this parameter as a
|
||||
/// hint to the Authentication Server. Passing this hint will either pre-fill the email box on the sign-in form
|
||||
/// or select the proper multi-login session, thereby simplifying the login flow.
|
||||
/// </summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("login_hint", Google.Apis.Util.RequestParameterType.Query)]
|
||||
public string LoginHint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the include granted scopes to determine if this authorization request should use
|
||||
/// incremental authorization (https://developers.google.com/+/web/api/rest/oauth#incremental-auth).
|
||||
/// If true and the authorization request is granted, the authorization will include any previous
|
||||
/// authorizations granted to this user/application combination for other scopes.
|
||||
/// </summary>
|
||||
/// <remarks>Currently unsupported for installed apps.</remarks>
|
||||
[Google.Apis.Util.RequestParameterAttribute("include_granted_scopes",
|
||||
Google.Apis.Util.RequestParameterType.Query)]
|
||||
public string IncludeGrantedScopes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a collection of user defined query parameters to facilitate any not explicitly supported
|
||||
/// by the library which will be included in the resultant authentication URL.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The name of this parameter is used only for the constructor and will not end up in the resultant query
|
||||
/// string.
|
||||
/// </remarks>
|
||||
[Google.Apis.Util.RequestParameterAttribute("user_defined_query_params",
|
||||
Google.Apis.Util.RequestParameterType.UserDefinedQueries)]
|
||||
public IEnumerable<KeyValuePair<string, string>> UserDefinedQueryParams { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new authorization code request with the given authorization server URL. This constructor sets
|
||||
/// the <see cref="AccessType"/> to <c>offline</c>.
|
||||
/// </summary>
|
||||
public GoogleAuthorizationCodeRequestUrl(Uri authorizationServerUrl)
|
||||
: base(authorizationServerUrl)
|
||||
{
|
||||
AccessType = "offline";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
Copyright 2014 Google Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
using Google.Apis.Requests;
|
||||
using Google.Apis.Requests.Parameters;
|
||||
|
||||
namespace Google.Apis.Auth.OAuth2.Requests
|
||||
{
|
||||
/// <summary>
|
||||
/// Google OAuth 2.0 request to revoke an access token as specified in
|
||||
/// https://developers.google.com/accounts/docs/OAuth2WebServer#tokenrevoke.
|
||||
/// </summary>
|
||||
class GoogleRevokeTokenRequest
|
||||
{
|
||||
private readonly Uri revokeTokenUrl;
|
||||
/// <summary>Gets the URI for token revocation.</summary>
|
||||
public Uri RevokeTokenUrl
|
||||
{
|
||||
get { return revokeTokenUrl; }
|
||||
}
|
||||
|
||||
/// <summary>Gets or sets the token to revoke.</summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("token")]
|
||||
public string Token { get; set; }
|
||||
|
||||
public GoogleRevokeTokenRequest(Uri revokeTokenUrl)
|
||||
{
|
||||
this.revokeTokenUrl = revokeTokenUrl;
|
||||
}
|
||||
|
||||
/// <summary>Creates a <see cref="System.Uri"/> which is used to request the authorization code.</summary>
|
||||
public Uri Build()
|
||||
{
|
||||
var builder = new RequestBuilder()
|
||||
{
|
||||
BaseUri = revokeTokenUrl
|
||||
};
|
||||
ParameterUtils.InitParameters(builder, this);
|
||||
return builder.BuildUri();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
Copyright 2013 Google Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Google.Apis.Auth.OAuth2.Requests
|
||||
{
|
||||
/// <summary>
|
||||
/// OAuth 2.0 request to refresh an access token using a refresh token as specified in
|
||||
/// http://tools.ietf.org/html/rfc6749#section-6.
|
||||
/// </summary>
|
||||
public class RefreshTokenRequest : TokenRequest
|
||||
{
|
||||
/// <summary>Gets or sets the Refresh token issued to the client.</summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("refresh_token")]
|
||||
public string RefreshToken { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new refresh code token request and sets grant_type to <c>refresh_token</c>.
|
||||
/// </summary>
|
||||
public RefreshTokenRequest()
|
||||
{
|
||||
GrantType = "refresh_token";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
Copyright 2013 Google Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Google.Apis.Auth.OAuth2.Requests
|
||||
{
|
||||
/// <summary>
|
||||
/// OAuth 2.0 request for an access token as specified in http://tools.ietf.org/html/rfc6749#section-4.
|
||||
/// </summary>
|
||||
public class TokenRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets space-separated list of scopes as specified in http://tools.ietf.org/html/rfc6749#section-3.3.
|
||||
/// </summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("scope")]
|
||||
public string Scope { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Grant type. Sets <c>authorization_code</c> or <c>password</c> or <c>client_credentials</c>
|
||||
/// or <c>refresh_token</c> or absolute URI of the extension grant type.
|
||||
/// </summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("grant_type")]
|
||||
public string GrantType { get; set; }
|
||||
|
||||
/// <summary>Gets or sets the client Identifier.</summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("client_id")]
|
||||
public string ClientId { get; set; }
|
||||
|
||||
/// <summary>Gets or sets the client Secret.</summary>
|
||||
[Google.Apis.Util.RequestParameterAttribute("client_secret")]
|
||||
public string ClientSecret { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
Copyright 2013 Google Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Google.Apis.Auth.OAuth2.Responses;
|
||||
using Google.Apis.Json;
|
||||
using Google.Apis.Requests.Parameters;
|
||||
using Google.Apis.Util;
|
||||
|
||||
namespace Google.Apis.Auth.OAuth2.Requests
|
||||
{
|
||||
/// <summary>Extension methods to <see cref="TokenRequest"/>.</summary>
|
||||
public static class TokenRequestExtenstions
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes the token request in order to receive a
|
||||
/// <see cref="Google.Apis.Auth.OAuth2.Responses.TokenResponse"/>. In case the token server returns an
|
||||
/// error, a <see cref="Google.Apis.Auth.OAuth2.Responses.TokenResponseException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <param name="request">The token request.</param>
|
||||
/// <param name="httpClient">The HTTP client used to create an HTTP request.</param>
|
||||
/// <param name="tokenServerUrl">The token server URL.</param>
|
||||
/// <param name="taskCancellationToken">Cancellation token to cancel operation.</param>
|
||||
/// <param name="clock">
|
||||
/// The clock which is used to set the
|
||||
/// <see cref="Google.Apis.Auth.OAuth2.Responses.TokenResponse.Issued"/> property.
|
||||
/// </param>
|
||||
/// <returns>Token response with the new access token.</returns>
|
||||
public static async Task<TokenResponse> ExecuteAsync(this TokenRequest request, HttpClient httpClient,
|
||||
string tokenServerUrl, CancellationToken taskCancellationToken, IClock clock)
|
||||
{
|
||||
var httpRequest = new HttpRequestMessage(HttpMethod.Post, tokenServerUrl);
|
||||
httpRequest.Content = ParameterUtils.CreateFormUrlEncodedContent(request);
|
||||
|
||||
var response = await httpClient.SendAsync(httpRequest, taskCancellationToken).ConfigureAwait(false);
|
||||
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var error = NewtonsoftJsonSerializer.Instance.Deserialize<TokenErrorResponse>(content);
|
||||
throw new TokenResponseException(error, response.StatusCode);
|
||||
}
|
||||
|
||||
// Gets the token and sets its issued time.
|
||||
var newToken = NewtonsoftJsonSerializer.Instance.Deserialize<TokenResponse>(content);
|
||||
newToken.IssuedUtc = clock.UtcNow;
|
||||
return newToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue