LineSDKAuthAPI.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // LineSDKAuthAPI.swift
  3. //
  4. // Copyright (c) 2016-present, LY Corporation. All rights reserved.
  5. //
  6. // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  7. // copy and distribute this software in source code or binary form for use
  8. // in connection with the web services and APIs provided by LY Corporation.
  9. //
  10. // As with any software that integrates with the LY Corporation platform, your use of this software
  11. // is subject to the LINE Developers Agreement [http://terms2.line.me/LINE_Developers_Agreement].
  12. // This copyright notice shall be included in all copies or substantial portions of the software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  15. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. @objcMembers
  22. public class LineSDKAuthAPI: NSObject {
  23. // MARK: - refreshAccessToken
  24. public static func refreshAccessToken(
  25. completionHandler completion: @escaping (LineSDKAccessToken?, Error?) -> Void
  26. )
  27. {
  28. refreshAccessToken(callbackQueue: .currentMainOrAsync, completionHandler: completion)
  29. }
  30. public static func refreshAccessToken(
  31. callbackQueue queue: LineSDKCallbackQueue,
  32. completionHandler completion: @escaping (LineSDKAccessToken?, Error?) -> Void
  33. )
  34. {
  35. API.Auth.refreshAccessToken(callbackQueue: queue.unwrapped) { result in
  36. result.map(LineSDKAccessToken.init).match(with: completion)
  37. }
  38. }
  39. // MARK: - revokeAccessToken
  40. public static func revokeAccessToken(
  41. completionHandler completion: @escaping (Error?) -> Void
  42. )
  43. {
  44. revokeAccessToken(nil, completionHandler: completion)
  45. }
  46. public static func revokeAccessToken(
  47. _ token: String?,
  48. completionHandler completion: @escaping (Error?) -> Void
  49. )
  50. {
  51. revokeAccessToken(token, callbackQueue: .currentMainOrAsync, completionHandler: completion)
  52. }
  53. public static func revokeAccessToken(
  54. _ token: String?,
  55. callbackQueue queue: LineSDKCallbackQueue,
  56. completionHandler completion: @escaping (Error?) -> Void
  57. )
  58. {
  59. API.Auth.revokeAccessToken(token, callbackQueue: queue.unwrapped) { result in
  60. result.matchFailure(with: completion)
  61. }
  62. }
  63. // MARK: - revokeRefreshToken
  64. public static func revokeRefreshToken(
  65. completionHandler completion: @escaping (Error?) -> Void
  66. )
  67. {
  68. revokeRefreshToken(nil, completionHandler: completion)
  69. }
  70. public static func revokeRefreshToken(
  71. _ token: String?,
  72. completionHandler completion: @escaping (Error?) -> Void
  73. )
  74. {
  75. revokeRefreshToken(token, callbackQueue: .currentMainOrAsync, completionHandler: completion)
  76. }
  77. public static func revokeRefreshToken(
  78. _ token: String?,
  79. callbackQueue queue: LineSDKCallbackQueue,
  80. completionHandler completion: @escaping (Error?) -> Void
  81. )
  82. {
  83. API.Auth.revokeRefreshToken(token, callbackQueue: queue.unwrapped) { result in
  84. result.matchFailure(with: completion)
  85. }
  86. }
  87. // MARK: - verifyAccessToken
  88. public static func verifyAccessToken(
  89. completionHandler completion: @escaping (LineSDKAccessTokenVerifyResult?, Error?) -> Void)
  90. {
  91. verifyAccessToken(nil, completionHandler: completion)
  92. }
  93. public static func verifyAccessToken(
  94. _ token: String?,
  95. completionHandler completion: @escaping (LineSDKAccessTokenVerifyResult?, Error?) -> Void)
  96. {
  97. verifyAccessToken(token, callbackQueue: .currentMainOrAsync, completionHandler: completion)
  98. }
  99. public static func verifyAccessToken(
  100. _ token: String?,
  101. callbackQueue queue: LineSDKCallbackQueue,
  102. completionHandler completion: @escaping (LineSDKAccessTokenVerifyResult?, Error?) -> Void)
  103. {
  104. API.Auth.verifyAccessToken(token, callbackQueue: queue.unwrapped) { result in
  105. result.map(LineSDKAccessTokenVerifyResult.init).match(with: completion)
  106. }
  107. }
  108. }