- private AuthorizationResponse GetAuthorizationResponse(IntPtr requestHandle)
- {
- AuthorizationResponse response = null;
- int ret = (int)OAuth2Error.None;
- IntPtr error = IntPtr.Zero;
-
- Interop.Manager.Oauth2AuthGrantCallback authGrantCb = (IntPtr responseHandle, IntPtr usrData) =>
- {
- if (responseHandle == IntPtr.Zero)
- {
- Log.Error(ErrorFactory.LogTag, "Error occured");
- throw (new ArgumentNullException());
- }
-
- Interop.Response.GetError(responseHandle, out error);
- if (error == IntPtr.Zero)
- {
- Log.Warn(ErrorFactory.LogTag, "Error occured");
- throw ErrorFactory.GetException(error);
- }
- else
- {
- IntPtr authorizationCode;
- ret = Interop.Response.GetAuthorizationCode(responseHandle, out authorizationCode);
- if (ret != (int)OAuth2Error.None)
- {
- Log.Error(ErrorFactory.LogTag, "Interop failed");
- throw ErrorFactory.GetException(ret);
- }
-
- IntPtr state;
- ret = Interop.Response.GetState(responseHandle, out state);
- if (ret != (int)OAuth2Error.None)
- {
- Log.Error(ErrorFactory.LogTag, "Interop failed");
- throw ErrorFactory.GetException(ret);
- }
-
- response = new AuthorizationResponse(responseHandle) { Code = Marshal.PtrToStringAnsi(authorizationCode), State = Marshal.PtrToStringAnsi(state) };
- }
- };
-
- ret = Interop.Manager.RequestAuthorizationGrant(_managerHandle, requestHandle, authGrantCb, IntPtr.Zero);
- Interop.Request.Destroy(requestHandle);
- if (ret != (int)OAuth2Error.None || error != IntPtr.Zero)
- {
- if (error != IntPtr.Zero)
- {
- throw ErrorFactory.GetException(error);
- }
- else
- {
- Log.Error(ErrorFactory.LogTag, "Interop failed");
- throw ErrorFactory.GetException(ret);
- }
- }
-
- return response;
- }