OLD | NEW |
(Empty) | |
| 1 /* |
| 2 Copyright 2013 Google Inc |
| 3 |
| 4 Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 you may not use this file except in compliance with the License. |
| 6 You may obtain a copy of the License at |
| 7 |
| 8 http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
| 10 Unless required by applicable law or agreed to in writing, software |
| 11 distributed under the License is distributed on an "AS IS" BASIS, |
| 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 See the License for the specific language governing permissions and |
| 14 limitations under the License. |
| 15 */ |
| 16 |
| 17 using System; |
| 18 using System.Collections.Generic; |
| 19 |
| 20 namespace Google.Apis.Auth.OAuth2.Responses |
| 21 { |
| 22 /// <summary> |
| 23 /// Authorization Code response for the redirect URL after end user grants o
r denies authorization as specified· |
| 24 /// in http://tools.ietf.org/html/rfc6749#section-4.1.2. |
| 25 /// <para> |
| 26 /// Check that <see cref="Code"/> is not <c>null</c> or empty to verify the
end-user granted authorization. |
| 27 /// </para> |
| 28 /// </summary> |
| 29 public class AuthorizationCodeResponseUrl |
| 30 { |
| 31 /// <summary>Gets or sets the authorization code generated by the author
ization server.</summary> |
| 32 public string Code { get; set; } |
| 33 |
| 34 /// <summary> |
| 35 /// Gets or sets the state parameter matching the state parameter in the
authorization request. |
| 36 /// </summary> |
| 37 public string State { get; set; } |
| 38 |
| 39 /// <summary> |
| 40 /// Gets or sets the error code (e.g. "invalid_request", "unauthorized_c
lient", "access_denied",· |
| 41 /// "unsupported_response_type", "invalid_scope", "server_error", "tempo
rarily_unavailable") as specified in· |
| 42 /// http://tools.ietf.org/html/rfc6749#section-4.1.2.1. |
| 43 /// </summary> |
| 44 public string Error { get; set; } |
| 45 |
| 46 /// <summary> |
| 47 /// Gets or sets the human-readable text which provides additional infor
mation used to assist the client· |
| 48 /// developer in understanding the error occurred. |
| 49 /// </summary> |
| 50 public string ErrorDescription { get; set; } |
| 51 |
| 52 /// <summary> |
| 53 /// Gets or sets the URI identifying a human-readable web page with prov
ides information about the error. |
| 54 /// </summary> |
| 55 public string ErrorUri { get; set; } |
| 56 |
| 57 /// <summary>Constructs a new authorization code response URL from the s
pecified dictionary.</summary> |
| 58 public AuthorizationCodeResponseUrl(IDictionary<string, string> queryStr
ing) |
| 59 { |
| 60 InitFromDictionary(queryString); |
| 61 } |
| 62 |
| 63 #region Constructs |
| 64 |
| 65 /// <summary>Constructs a new authorization code response URL from the s
pecified query string.</summary> |
| 66 public AuthorizationCodeResponseUrl(string query) |
| 67 { |
| 68 var pairs = query.Split('&'); |
| 69 var queryString = new Dictionary<string, string>(); |
| 70 foreach (var pair in pairs) |
| 71 { |
| 72 var keyValue = pair.Split('='); |
| 73 queryString[keyValue[0]] = keyValue[1]; |
| 74 } |
| 75 |
| 76 InitFromDictionary(queryString); |
| 77 } |
| 78 |
| 79 /// <summary>Initializes this instance from the input dictionary.</summa
ry> |
| 80 private void InitFromDictionary(IDictionary<string, string> queryString) |
| 81 { |
| 82 //TODO(peleyal): improve the following code and make it a utility |
| 83 IDictionary<string, Action<string>> setters = new Dictionary<string,
Action<string>>(); |
| 84 setters["code"] = v => Code = v; |
| 85 setters["state"] = v => State = v; |
| 86 setters["error"] = v => Error = v; |
| 87 setters["error_description"] = v => ErrorDescription = v; |
| 88 setters["error_uri"] = v => ErrorUri = v; |
| 89 |
| 90 Action<string> setter; |
| 91 foreach (var pair in queryString) |
| 92 { |
| 93 if (setters.TryGetValue(pair.Key, out setter)) |
| 94 { |
| 95 setter(pair.Value); |
| 96 } |
| 97 } |
| 98 } |
| 99 |
| 100 /// <summary>Constructs a new empty authorization code response URL.</su
mmary> |
| 101 public AuthorizationCodeResponseUrl() |
| 102 { |
| 103 } |
| 104 |
| 105 #endregion |
| 106 } |
| 107 } |
OLD | NEW |