Exemple #1
0
 public void DeviceAuthentication(AuthCallback _authcallback)
 {
     new GameSparks.Api.Requests.DeviceAuthenticationRequest().Send((response) =>
     {
         _authcallback(response);
     });
 }
Exemple #2
0
        protected override AuthToken GetAccessToken(AuthCallback authCallback)
        {
            var reqParams = new Dictionary <string, object>
            {
                { "app_id", config.ClientId },
                { "secret", config.ClientSecret },
                { "code", authCallback.Code },
                { "grant_type", "authorization_code" },
            };

            var response          = HttpUtils.RequestFormPost(source.AccessToken(), reqParams.SpellParams());
            var accessTokenObject = response.ParseObject();

            this.checkResponse(accessTokenObject);

            var authToken = new AuthToken
            {
                AccessToken  = accessTokenObject.GetString("access_token"),
                ExpireIn     = accessTokenObject.GetInt32("expires_in"),
                RefreshToken = accessTokenObject.GetString("refresh_token"),
                Code         = authCallback.Code
            };

            return(authToken);
        }
        protected override AuthToken getAccessToken(AuthCallback authCallback)
        {
            var reqParams = new Dictionary <string, object>
            {
                { "client_id", config.clientId },
                { "redirect_uri", config.clientSecret },
                { "code", authCallback.code },
                { "grant_type", "authorization_code" },
            };

            var reqHeaders = this.getSpecialHeader(this.getRequestId());

            var response          = HttpUtils.RequestFormPost(source.accessToken(), reqParams.spellParams(), reqHeaders);
            var accessTokenObject = response.parseObject();

            this.checkResponse(accessTokenObject);

            var authToken = new AuthToken
            {
                accessToken  = accessTokenObject.getString("access_token"),
                expireIn     = accessTokenObject.getInt32("expires_in"),
                refreshToken = accessTokenObject.getString("refresh_token"),
                tokenType    = accessTokenObject.getString("token_type"),
                code         = authCallback.code
            };

            return(authToken);
        }
        protected override AuthToken GetAccessToken(AuthCallback authCallback)
        {
            var authToken = new AuthToken();

            authToken.AccessCode = authCallback.Code;
            return(authToken);
        }
Exemple #5
0
        protected override AuthToken getAccessToken(AuthCallback authCallback)
        {
            var reqHeaders = new Dictionary <string, object>
            {
                { "Content-Type", "application/x-www-form-urlencoded" },
            };
            var reqParams = new Dictionary <string, object>
            {
                { "client_id", config.clientId },
                { "client_secret", config.clientSecret },
                { "code", authCallback.code },
                { "grant_type", "code" },
            };

            var response = HttpUtils.RequestPost(source.accessToken(), reqParams.spellParams(), reqHeaders);

            var accessTokenObject = response.parseObject();

            this.checkResponse(accessTokenObject);

            var authToken = new AuthToken();

            authToken.accessToken  = accessTokenObject.getString("access_token");
            authToken.refreshToken = accessTokenObject.getString("refresh_token");

            return(authToken);
        }
Exemple #6
0
        /**
         * 微信的特殊性,此时返回的信息同时包含 openid 和 access_token
         *
         * @param authCallback 回调返回的参数
         * @return 所有信息
         */
        protected override AuthToken getAccessToken(AuthCallback authCallback)
        {
            AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();

            request.GrantType = "authorization_code";
            request.Code      = authCallback.auth_code;
            AlipaySystemOauthTokenResponse response = null;

            try
            {
                response = this.aopClient.Execute(request);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            if (response.IsError)
            {
                throw new Exception(response.SubMsg);
            }

            var authToken = new AuthToken();

            authToken.accessToken  = response.AccessToken;
            authToken.uid          = response.UserId;
            authToken.expireIn     = Convert.ToInt32(response.ExpiresIn);
            authToken.refreshToken = response.RefreshToken;
            authToken.userId       = response.AlipayUserId;

            return(authToken);
        }
Exemple #7
0
        /// <summary>
        /// 授权回调方法
        /// </summary>
        /// <param name="authSource"></param>
        /// <param name="authCallback"></param>
        /// <returns></returns>
        public ActionResult Callback(string authSource, AuthCallback authCallback)
        {
            AuthRequestFactory authRequest = new AuthRequestFactory();
            var request      = authRequest.getRequest(authSource);
            var authResponse = request.login(authCallback);

            return(Content(JsonConvert.SerializeObject(authResponse)));
        }
Exemple #8
0
        /// <summary>
        /// 钉钉callback
        /// </summary>
        /// <param name="authSource"></param>
        /// <param name="authCallback"></param>
        /// <returns></returns>
        public ActionResult DingTalkCallback(AuthCallback authCallback)
        {
            AuthRequestFactory authRequest = new AuthRequestFactory();
            var request      = authRequest.getRequest("DINGTALK_SCAN");
            var authResponse = request.login(authCallback);

            return(Content(JsonConvert.SerializeObject(authResponse)));
        }
 /// <summary>
 /// 获取 accessToken 的 url 以及参数。
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 protected virtual string GetAccessTokenUrl(AuthCallback authCallback)
 {
     return(UrlBuilder.FromBaseUrl(_source.AccessToken)
            .QueryParam("grant_type", "authorization_code")
            .QueryParam("client_id", _config.ClientId)
            .QueryParam("client_secret", _config.ClientSecret)
            .QueryParam("redirect_uri", _config.RedirectUri)
            .QueryParam("code", authCallback.Code)
            .Build());
 }
 public void RegisterInfoCallback(AuthCallback callback)
 {
     if (null == infoCallback)
     {
         infoCallback = new AuthCallback(callback);
     }
     else
     {
         infoCallback += callback;
     }
 }
 public void RegisterAuthCallback(AuthCallback callback)
 {
     if (null == authCallback)
     {
         authCallback = new AuthCallback(callback);
     }
     else
     {
         authCallback += callback;
     }
 }
Exemple #12
0
        static public int OpenPasswordProtectedDocument(Form1 Parent)
        {
            string    sPath    = System.Environment.CurrentDirectory + "\\Documents\\PasswordProtected.pdf";
            IAFS_Inst fsInst   = (IAFS_Inst)Parent.m_pxcInst.GetExtension("AFS");
            IAFS_Name destPath = fsInst.DefaultFileSys.StringToName(sPath);             //Converting string to name

            Parent.CloseDocument();
            AuthCallback clbk = new AuthCallback();

            Parent.m_CurDoc = Parent.m_pxcInst.OpenDocumentFrom(destPath, clbk);

            return((int)Form1.eFormUpdateFlags.efuf_All);
        }
Exemple #13
0
        protected override AuthToken getAccessToken(AuthCallback authCallback)
        {
            string response          = doGetAuthorizationCode(authCallback.code);
            var    accessTokenObject = response.parseObject();

            this.checkResponse(accessTokenObject);

            var authToken = new AuthToken();

            authToken.accessToken  = accessTokenObject.getString("access_token");
            authToken.expireIn     = accessTokenObject.getInt32("expires_in");
            authToken.refreshToken = accessTokenObject.getString("refresh_token");
            return(authToken);
        }
Exemple #14
0
        protected override AuthToken GetAccessToken(AuthCallback authCallback)
        {
            var response          = DoGetAuthorizationCode(authCallback.Code);
            var accessTokenObject = response.ParseObject();

            this.CheckResponse(accessTokenObject);

            var authToken = new AuthToken();

            authToken.AccessToken = accessTokenObject.GetString("access_token");
            authToken.ExpireIn    = accessTokenObject.GetInt32("expires_in");
            authToken.OpenId      = accessTokenObject.GetString("open_id");
            authToken.Code        = authCallback.Code;
            return(authToken);
        }
Exemple #15
0
        /**
         * 微信的特殊性,此时返回的信息同时包含 openid 和 access_token
         *
         * @param authCallback 回调返回的参数
         * @return 所有信息
         */
        protected override AuthToken getAccessToken(AuthCallback authCallback)
        {
            string response = doGetAuthorizationCode(accessTokenUrl(authCallback.code));
            var    jsonObj  = response.parseObject();

            this.checkResponse(jsonObj);

            var authToken = new AuthToken();

            authToken.accessToken = jsonObj.getString("access_token");
            authToken.expireIn    = jsonObj.getInt32("expires_in");
            authToken.code        = authCallback.code;

            return(authToken);
        }
Exemple #16
0
    /// <summary>
    /// Sends an authentication request or registration request to GS.
    /// </summary>
    /// <param name="_callback1">Auth-Response</param>
    /// <param name="_callback2">Registration-Response</param>
    public void AuthenticateUser(AuthCallback _authcallback)
    {
        new DeviceAuthenticationRequest()
        .Send((response) =>
        {
            Debug.Log("DeviceAuthenticationRequest.JSON:" + response.JSONString);
            Debug.Log("DeviceAuthenticationRequest.HasErrors:" + response.HasErrors);
            Debug.Log("DeviceAuthenticationRequest.UserId:" + response.UserId);

            if (!response.HasErrors)
            {
                _authcallback(response);
            }
        });
    }
Exemple #17
0
        /**
         * 获取access token
         *
         * @param authCallback 授权成功后的回调参数
         * @return token
         * @see AuthDefaultRequest#authorize()
         * @see AuthDefaultRequest#authorize(String)
         */
        protected override AuthToken getAccessToken(AuthCallback authCallback)
        {
            var reqParams = new Dictionary <string, object>
            {
                { "grant_type", "authorization_code" },
                { "code", authCallback.authorization_code },
                { "client_id", config.clientId },
                { "client_secret", config.clientSecret },
                { "redirect_uri", config.redirectUri },
            };

            var response = HttpUtils.RequestFormPost(source.accessToken(), reqParams.spellParams());

            return(getAuthToken(response));
        }
        protected override AuthToken GetAccessToken(AuthCallback authCallback)
        {
            var response          = DoPostAuthorizationCode(authCallback.Code);
            var accessTokenObject = response.ParseObject();

            this.checkResponse(accessTokenObject);

            var authToken = new AuthToken
            {
                AccessToken = accessTokenObject.GetString("access_token"),
                TokenType   = accessTokenObject.GetString("token_type"),
                Code        = authCallback.Code
            };

            return(authToken);
        }
Exemple #19
0
        public virtual AuthResponse login(AuthCallback authCallback)
        {
            try
            {
                AuthChecker.checkCode(source, authCallback);
                AuthChecker.checkState(authCallback.state, source, authStateCache);

                AuthToken authToken = this.getAccessToken(authCallback);
                AuthUser  user      = this.getUserInfo(authToken);
                return(new AuthResponse(Convert.ToInt32(AuthResponseStatus.SUCCESS), null, user));
            }
            catch (Exception e)
            {
                return(this.responseError(e));
            }
        }
Exemple #20
0
        protected override AuthToken getAccessToken(AuthCallback authCallback)
        {
            string response          = doPostAuthorizationCode(authCallback.code);
            var    accessTokenObject = response.parseStringObject();

            this.checkResponse(accessTokenObject);

            var authToken = new AuthToken();

            authToken.accessToken = accessTokenObject.getString("access_token");
            authToken.tokenType   = accessTokenObject.getString("token_type");
            authToken.scope       = accessTokenObject.getString("scope");
            authToken.code        = authCallback.code;

            return(authToken);
        }
Exemple #21
0
        protected override AuthToken GetAccessToken(AuthCallback authCallback)
        {
            string response          = DoPostAuthorizationCode(authCallback.Code);
            var    accessTokenObject = response.ParseObject();

            this.checkResponse(accessTokenObject);

            var authToken = new AuthToken();

            authToken.AccessToken  = accessTokenObject.GetString("access_token");
            authToken.RefreshToken = accessTokenObject.GetString("refresh_token");
            authToken.Uid          = accessTokenObject.GetString("uid");
            authToken.ExpireIn     = accessTokenObject.GetInt32("expires_in");
            authToken.Code         = authCallback.Code;
            return(authToken);
        }
Exemple #22
0
        protected override AuthToken getAccessToken(AuthCallback authCallback)
        {
            var response          = doPostAuthorizationCode(authCallback.code);
            var accessTokenObject = response.parseObject();

            this.checkResponse(accessTokenObject);

            var authToken = new AuthToken
            {
                accessToken = accessTokenObject.getString("access_token"),
                expireIn    = accessTokenObject.getInt32("expires_in"),
                tokenType   = accessTokenObject.getString("token_type"),
                code        = authCallback.code
            };

            return(authToken);
        }
Exemple #23
0
        protected override AuthToken GetAccessToken(AuthCallback authCallback)
        {
            var response          = DoPostAuthorizationCode(authCallback.Code);
            var accessTokenObject = response.ParseObject();

            this.checkResponse(accessTokenObject);

            var authToken = new AuthToken();

            authToken.AccessToken = accessTokenObject.GetString("access_token");
            authToken.ExpireIn    = accessTokenObject.GetInt32("expires_in");
            authToken.IdToken     = accessTokenObject.GetString("id_token");
            authToken.TokenType   = accessTokenObject.GetString("token_type");
            authToken.Scope       = accessTokenObject.GetString("scope");

            return(authToken);
        }
Exemple #24
0
        /**
         * 校验回调传回的code
         * <p>
         * {@code v1.10.0}版本中改为传入{@code source}和{@code callback},对于不同平台使用不同参数接受code的情况统一做处理
         *
         * @param source   当前授权平台
         * @param callback 从第三方授权回调回来时传入的参数集合
         * @since 1.8.0
         */
        public static void checkCode(IAuthSource source, AuthCallback callback)
        {
            string code = callback.code;

            if (source.getName().ToUpper().Equals(DefaultAuthSourceEnum.ALIPAY_MP.ToString()))
            {
                code = callback.auth_code;
            }
            else if ("HUAWEI".Equals(source.getName().ToUpper()))
            {
                code = callback.authorization_code;
            }
            if (string.IsNullOrWhiteSpace(code))
            {
                throw new Exception(AuthResponseStatus.ILLEGAL_CODE.GetDesc());
            }
        }
 public void AuthenticateFacebookUser(string fbAccessToken, AuthCallback callback = null)
 {
     new FacebookConnectRequest().SetAccessToken(fbAccessToken).Send((response) =>
     {
         if (callback != null)
         {
             if (response.HasErrors)
             {
                 callback(new AuthReply(false, false, "GS failed to fetch FB user profile, " + response.Errors.ToString()));
             }
             else
             {
                 callback(new AuthReply(true, response.ScriptData.GetBoolean("updateFromFb").Value));
             }
         }
     });
 }
 public void AuthenticateUser(string _userName, string _password, AuthCallback _authcallback)
 {
     //sends an authentication request with the details included.
     new AuthenticationRequest()
     .SetUserName(_userName)
     .SetPassword(_password)
     .Send((authResp) => {
         if (!authResp.HasErrors)
         {
             Debug.Log("Authentication Successful...");
             _authcallback(authResp);
         }
         else
         {
             Debug.LogWarning("GSM| Error Authenticating User \n" + authResp.Errors.JSON);
         }
     });
 }
        private void Authenticate()
        {
            FingerprintManager fingerprint = this.GetSystemService(FingerprintService) as FingerprintManager;
            KeyguardManager    keyGuard    = GetSystemService(KeyguardService) as KeyguardManager;

            Android.Content.PM.Permission permission = CheckSelfPermission(Android.Manifest.Permission.UseFingerprint);
            if (fingerprint.IsHardwareDetected &&
                keyGuard.IsKeyguardSecure &&
                fingerprint.HasEnrolledFingerprints &&
                permission == Android.Content.PM.Permission.Granted)
            {
                const int           flags              = 0;
                CryptoObjectFactory cryptoObject       = new CryptoObjectFactory();
                CancellationSignal  cancellationSignal = new CancellationSignal();
                FingerprintManager.AuthenticationCallback authCallback = new AuthCallback(this);
                fingerprint.Authenticate(cryptoObject.BuildCryptoObject(), cancellationSignal, flags, authCallback, null);
            }
        }
Exemple #28
0
        protected override AuthToken GetAccessToken(AuthCallback authCallback)
        {
            var response          = DoPostAuthorizationCode(authCallback.Code);
            var accessTokenObject = response.ParseObject();

            if (accessTokenObject.ContainsKey("error"))
            {
                throw new Exception(accessTokenObject.GetString("error_description"));
            }

            var authToken = new AuthToken();

            authToken.AccessToken = accessTokenObject.GetString("access_token");
            authToken.Uid         = accessTokenObject.GetString("uid");
            authToken.OpenId      = accessTokenObject.GetString("uid");
            authToken.ExpireIn    = accessTokenObject.GetInt32("expires_in");
            authToken.Code        = authCallback.Code;

            return(authToken);
        }
Exemple #29
0
        protected override AuthToken GetAccessToken(AuthCallback authCallback)
        {
            string accessTokenUrl = this.accessTokenUrl(authCallback.Code);

            var reqHeaders = new Dictionary <string, object>
            {
                { "Content-Type", "application/x-www-form-urlencoded" },
            };
            var reqParams = accessTokenUrl.ParseUrlObject();

            var response = HttpUtils.RequestPost(source.AccessToken(), reqParams.SpellParams(), reqHeaders);

            var accessTokenObject = response.ParseObject();

            this.checkResponse(accessTokenObject);

            var authToken = new AuthToken();

            authToken.AccessToken = accessTokenObject.GetString("access_token");
            authToken.ExpireIn    = accessTokenObject.GetInt32("expires");
            return(authToken);
        }
Exemple #30
0
        protected override AuthToken GetAccessToken(AuthCallback authCallback)
        {
            var jObject = DoPostAuthorizationCode(authCallback);

            if (jObject["error"] != null)
            {
                var error            = jObject["error"].ToString();
                var errorDescription = jObject["error_description"].ToString();
                throw new AuthException(error, errorDescription);
            }

            var accessToken = jObject["access_token"].ToString();
            var scope       = jObject["scope"].ToString();
            var tokenType   = jObject["token_type"].ToString();

            return(new AuthToken
            {
                AccessToken = accessToken,
                Scope = scope,
                TokenType = tokenType
            });
        }