Deprecate of Tizen.Account.OAuth2 (#1094)
[platform/core/csapi/tizenfx.git] / src / Tizen.Account.OAuth2 / Tizen.Account.OAuth2 / TokenResponse.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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.Runtime.InteropServices;
19
20 namespace Tizen.Account.OAuth2
21 {
22     /// <summary>
23     /// The response from authroization server containing access token and an optional refresh token.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     [Obsolete]
27     public class TokenResponse
28     {
29         private bool _disposed = false;
30         private IntPtr _responseHandle;
31
32         internal TokenResponse(IntPtr handle)
33         {
34             _responseHandle = handle;
35         }
36
37         /// <summary>
38         /// Destructor of the AuthorizationResponse class.
39         /// </summary>
40         /// <since_tizen> 3 </since_tizen>
41         ~TokenResponse()
42         {
43             Dispose(false);
44         }
45
46         /// <summary>
47         /// The access token
48         /// </summary>
49         /// <since_tizen> 3 </since_tizen>
50         [Obsolete]
51         public AccessToken AccessToken { get; internal set; }
52
53         /// <summary>
54         /// The state parameter present in authorization request.
55         /// </summary>
56         /// <since_tizen> 3 </since_tizen>
57         /// <remarks>
58         /// The value can be null depending on the server specifications.
59         /// </remarks>
60         [Obsolete]
61         public string State { get; internal set; }
62
63         /// <summary>
64         /// The refresh token. The value will be null if authorization server doesn't return a refresh token.
65         /// </summary>
66         /// <since_tizen> 3 </since_tizen>
67         /// <remarks>
68         /// Issuing a refresh token is optional at the discretion of the authorization server.
69         /// </remarks>
70         [Obsolete]
71         public RefreshToken RefreshToken { get; internal set; }
72
73         /// <summary>
74         /// Gets the value of the key received from service provider
75         /// </summary>
76         /// <since_tizen> 3 </since_tizen>
77         /// <returns>The value of respecitve key </returns>
78         /// <exception cref="System.ArgumentException">Thrown when the key does not exist or when there is an invalid parameter.</exception>
79         [Obsolete]
80         public string GetCustomValue(string key)
81         {
82             IntPtr value;
83             int ret = Interop.Response.GetCustomData(_responseHandle, key, out value);
84             if (ret != (int)OAuth2Error.None)
85             {
86                 Log.Error(ErrorFactory.LogTag, "Interop failed");
87                 throw ErrorFactory.GetException(ret);
88             }
89             return Marshal.PtrToStringAnsi(value);
90         }
91
92         /// <summary>
93         /// Releases any unmanaged resources used by this object.
94         /// </summary>
95         /// <since_tizen> 3 </since_tizen>
96         [Obsolete]
97         public void Dispose()
98         {
99             Dispose(true);
100             GC.SuppressFinalize(this);
101         }
102
103         /// <summary>
104         /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
105         /// </summary>
106         /// <since_tizen> 3 </since_tizen>
107         /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
108         [Obsolete]
109         protected virtual void Dispose(bool disposing)
110         {
111             if (_disposed)
112                 return;
113
114             if (disposing)
115             {
116                 // Free managed objects
117             }
118
119             Interop.Response.Destroy(_responseHandle);
120             _disposed = true;
121         }
122     }
123 }