2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Runtime.InteropServices;
20 namespace Tizen.Account.OAuth2
23 /// The response from authroization server containing access token and an optional refresh token.
25 /// <since_tizen> 3 </since_tizen>
26 public class TokenResponse
28 private bool _disposed = false;
29 private IntPtr _responseHandle;
31 internal TokenResponse(IntPtr handle)
33 _responseHandle = handle;
37 /// Destructor of the AuthorizationResponse class.
39 /// <since_tizen> 3 </since_tizen>
48 /// <since_tizen> 3 </since_tizen>
49 public AccessToken AccessToken { get; internal set; }
52 /// The state parameter present in authorization request.
54 /// <since_tizen> 3 </since_tizen>
56 /// The value can be null depending on the server specifications.
58 public string State { get; internal set; }
61 /// The refresh token. The value will be null if authorization server doesn't return a refresh token.
63 /// <since_tizen> 3 </since_tizen>
65 /// Issuing a refresh token is optional at the discretion of the authorization server.
67 public RefreshToken RefreshToken { get; internal set; }
70 /// Gets the value of the key received from service provider
72 /// <since_tizen> 3 </since_tizen>
73 /// <returns>The value of respecitve key </returns>
74 /// <exception cref="System.ArgumentException">Thrown when the key does not exist or when there is an invalid parameter.</exception>
75 public string GetCustomValue(string key)
78 int ret = Interop.Response.GetCustomData(_responseHandle, key, out value);
79 if (ret != (int)OAuth2Error.None)
81 Log.Error(ErrorFactory.LogTag, "Interop failed");
82 throw ErrorFactory.GetException(ret);
84 return Marshal.PtrToStringAnsi(value);
88 /// Releases any unmanaged resources used by this object.
90 /// <since_tizen> 3 </since_tizen>
94 GC.SuppressFinalize(this);
98 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
100 /// <since_tizen> 3 </since_tizen>
101 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
102 protected virtual void Dispose(bool disposing)
109 // Free managed objects
112 Interop.Response.Destroy(_responseHandle);