public object Process(HttpContextBase context) { Arguments.NotNull(context, "context"); AuthResponseType responseType = AuthResponseType.AccessToken; var responseTypeString = MessageUtility.TryGetString(context.Request, Protocal.RESPONSE_TYPE); if (!String.IsNullOrEmpty(responseTypeString)) { if (!AuthResponseTypeExtend.TryParse(responseTypeString, out responseType)) { throw new OAuthException(AccessTokenRequestErrorCode.InvalidRequest, "wrong response_type value", 400); } } var request = context.Request; switch (responseType) { case AuthResponseType.AccessToken: var tokenRequest = MessageUtility.ParseTokenRequest(request); tokenRequest.OAuthService = this; return(tokenRequest.Token()); case AuthResponseType.AuthorizationCode: var authorizeRequest = MessageUtility.ParseAuthRequest(request); authorizeRequest.OAuthService = this; return(authorizeRequest.Authorize()); } return(null); }
public static string ToValue(this AuthResponseType responseType) { switch (responseType) { case AuthResponseType.AccessToken: return("token"); case AuthResponseType.AuthorizationCode: return("code"); } return(""); }
public static bool TryParse(string value, out AuthResponseType responseType) { responseType = AuthResponseType.AuthorizationCode; if (String.IsNullOrEmpty(value)) { return(false); } value = value.ToLower(); switch (value) { case "token": responseType = AuthResponseType.AccessToken; return(true); case "code": responseType = AuthResponseType.AuthorizationCode; return(true); } return(false); }
/// <summary> /// 开始授权。 /// </summary> /// <param name="appKey">开发者中心注册应用时获得的API KEY</param> /// <param name="redirectUrl">授权流程结束后要跳转回的URL地址,该地址必须在开发者中心注册的网站地址之后</param> /// <param name="authType"></param> /// <param name="responseType"></param> public static void Auth(string appKey, string redirectUrl, AuthType authType = AuthType.SinaWeibo, AuthResponseType responseType = AuthResponseType.Code) { #if UNITY_ANDROID AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject activity = cls_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity"); activity.Call("bindInfo", appKey, redirectUrl, (int)authType, (int)responseType); #elif UNITY_IPHONE _weiboAuth(appKey, redirectUrl, (int)authType, (int)responseType); #endif }