猎豆优选

MtopAuthProtocol.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // MtopAuthProtocol.h
  3. // mtopext
  4. //
  5. // Created by jiangpan on 2017/8/23.
  6. // Copyright © 2017年 taobao. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. /**
  10. * 授权标记
  11. */
  12. typedef enum {
  13. /**
  14. * 只走AutoAuth,失败什么都不做
  15. */
  16. AuthOptionAutoAuthOnly = 1,
  17. /**
  18. * 先走AutoAuth,失败再拉授权页面
  19. */
  20. AuthOptionAutoAuthAndManualAuth,
  21. } AuthOption;
  22. /**
  23. * 授权成功回调
  24. * @param isSuccessful YES表示授权成功(auto auth或者manual auth),NO表示授权失败(只可能发生在authOptionAutoauthOnly)
  25. * @param authResult 授权成功的情况下返回的授权结果(包含授权态)
  26. */
  27. typedef void (^AUTH_COMPLETION_HANDLER) (BOOL isSuccessful, NSDictionary* authResult);
  28. /**
  29. * 授权取消回调
  30. * @param flags 用户手动取消授权页面
  31. */
  32. typedef void (^AUTH_CANCELATION_HANDLER) (void);
  33. @interface AuthParamObj:NSObject
  34. @property (nonatomic,strong) NSDictionary *authParam; // 授权参数
  35. @property (nonatomic,copy) NSString *openAppkey; // 三方授权业务的appkey
  36. - (instancetype)initWithAppkey:(NSString *)appkey andAuthParam:(NSDictionary *)authParam;
  37. @end
  38. @protocol MtopAuthProtocol <NSObject>
  39. @required
  40. /*!
  41. * 判断当前用户是否有授权会话
  42. * @return
  43. * YES 本地有会话且本地判断会话未过期,但服务端可能判定会话无效
  44. * NO 本地无会话或本地判断会话已过期
  45. */
  46. - (BOOL)isValidAuth:(AuthParamObj *)authParam;
  47. /*
  48. * 触发授权操作
  49. * @param authOption 授权选项 参看 <code>authOption</code>
  50. * @param completionHandler 授权成功后回调
  51. * @param cancelationHandler 授权用户取消后回调
  52. * @param authParam 授权参数对象
  53. */
  54. - (void)authWithAuthOption:(AuthOption)authOption
  55. completionHandler:(AUTH_COMPLETION_HANDLER)completionHandler
  56. cancelationHandler:(AUTH_CANCELATION_HANDLER)cancelationHandler
  57. authParam:(AuthParamObj *)authParam;
  58. /*
  59. * 基本同上
  60. * @param extraInfoDict 额外参数
  61. */
  62. - (void)authWithAuthOption:(AuthOption)authOption
  63. extraInfo:(NSDictionary *)extraInfoDict
  64. completionHandler:(AUTH_COMPLETION_HANDLER)completionHandler
  65. cancelationHandler:(AUTH_CANCELATION_HANDLER)cancelationHandler
  66. authParam:(AuthParamObj *)authParam;
  67. /*!
  68. * 获取当前授权会话信息
  69. * @return
  70. * 会话信息
  71. * sid -> session id (NSString*)
  72. * userId -> 用户id (NSString*)
  73. * ecode -> ecode (NSString*)
  74. * nick -> 用户nick (NSString*)
  75. * authToken -> 授权令牌 (NSString*)
  76. * ssoToken -> sso令牌 (NSString*)
  77. * topSession -> top授权 (NSString*)
  78. * cookie -> cookie (NSString*)
  79. * ......
  80. */
  81. - (NSDictionary *)currentSession:(AuthParamObj *)authParam;
  82. /*!
  83. * 返回当前authCenter是否已经在处理授权行为
  84. * @return YES 已经有在处理中的授权行为
  85. * NO 没有正在处理的授权行为
  86. */
  87. - (BOOL)isProcessingAuth:(AuthParamObj *)authParam;
  88. /*!
  89. * 标识本地auth已经失效
  90. */
  91. - (void)markInvalidAuth:(AuthParamObj *)authParam;
  92. @end