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 containing authroization code from the authorization server.
25 /// <since_tizen> 3 </since_tizen>
26 public class AuthorizationResponse : IDisposable
28 private bool _disposed = false;
29 private IntPtr _responseHandle;
31 internal AuthorizationResponse(IntPtr handle)
33 _responseHandle = handle;
37 /// Destructor of the AuthorizationResponse class.
39 /// <since_tizen> 3 </since_tizen>
40 ~AuthorizationResponse()
46 /// The authroization code.
48 /// <since_tizen> 3 </since_tizen>
49 public string Code { 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 /// Custom key-value parameter received from service provider
63 /// <since_tizen> 3 </since_tizen>
65 /// The return value can be null depending on the server specifications.
67 public string GetCustomValue(string key)
69 IntPtr value = IntPtr.Zero;
70 int ret = Interop.Response.GetCustomData(_responseHandle, key, out value);
71 if (ret != (int)OAuth2Error.None)
73 Log.Error(ErrorFactory.LogTag, "Interop failed");
74 throw ErrorFactory.GetException(ret);
76 return Marshal.PtrToStringAnsi(value);
80 /// Releases any unmanaged resources used by this object.
82 /// <since_tizen> 3 </since_tizen>
86 GC.SuppressFinalize(this);
90 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
92 /// <since_tizen> 3 </since_tizen>
93 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
94 protected virtual void Dispose(bool disposing)
101 // Free managed objects
104 Interop.Response.Destroy(_responseHandle);