예제 #1
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        protected internal string User(Option option)
        {
            option.CheckByKeys(new string[] { "registerInClient", "id" });
            string query = "  query user($id: String!, $registerInClient: String!){\n" +
                           "    user(id: $id, registerInClient: $registerInClient) {\n" +
                           "        _id\n" +
                           "        email\n" +
                           "        emailVerified\n" +
                           "        username\n" +
                           "        nickname\n" +
                           "        company\n" +
                           "        photo\n" +
                           "        browser\n" +
                           "        registerInClient\n" +
                           "        registerMethod\n" +
                           "        oauth\n" +
                           "        token\n" +
                           "        tokenExpiredAt\n" +
                           "        loginsCount\n" +
                           "        lastLogin\n" +
                           "        lastIP\n" +
                           "        signedUp\n" +
                           "        blocked\n" +
                           "        isDeleted\n" +
                           "    }\n" +
                           "\n" +
                           "}";
            PostEntity postEntity = new PostEntity(query, option);
            Dictionary <HttpRequestHeader, string> headers = new Dictionary <HttpRequestHeader, string>();

            headers.Add(HttpRequestHeader.Authorization, "Bearer " + ownerToken); //"Authorization"
            string resJson = HttpClientHelper.DoPost(usersUrl, postEntity, headers);

            return(resJson);
        }
예제 #2
0
        /// <summary>
        /// 验证修改密码验证码
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        protected internal string VerifyResetPasswordVerifyCode(Option option)
        {
            if (ownerToken == "" || ownerToken == null)
            {
                throw new AuthingException("can not find ownerToken,please login again");
            }
            option.CheckByKeys(new string[] { "email", "client", "verifyCode" });
            string query = "mutation verifyResetPasswordVerifyCode(\n" +
                           "    $email: String!,\n" +
                           "    $client: String!,\n" +
                           "    $verifyCode: String!\n" +
                           ") {\n" +
                           "    verifyResetPasswordVerifyCode(\n" +
                           "        email: $email,\n" +
                           "        client: $client,\n" +
                           "        verifyCode: $verifyCode\n" +
                           "    ) {\n" +
                           "          message\n" +
                           "          code\n" +
                           "    }\n" +
                           "}";
            PostEntity postEntity = new PostEntity(query, option);
            Dictionary <HttpRequestHeader, string> headers = new Dictionary <HttpRequestHeader, string>();

            headers.Add(HttpRequestHeader.Authorization, "Bearer " + ownerToken); //"Authorization"
            string resJson = HttpClientHelper.DoPost(usersUrl, postEntity, headers);

            return(resJson);
        }
예제 #3
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        protected internal string ChangePassword(Option option)
        {
            if (ownerToken == "" || ownerToken == null)
            {
                throw new AuthingException("can not find ownerToken,please login again");
            }
            option.CheckByKeys(new string[] { "email", "client", "verifyCode", "password" });
            string query = "mutation changePassword(\n" +
                           "    $email: String!,\n" +
                           "    $client: String!,\n" +
                           "    $password: String!,\n" +
                           "    $verifyCode: String!\n" +
                           "){\n" +
                           "    changePassword(\n" +
                           "        email: $email,\n" +
                           "        client: $client,\n" +
                           "        password: $password,\n" +
                           "        verifyCode: $verifyCode\n" +
                           "    ) {\n" +
                           "        _id\n" +
                           "        email\n" +
                           "        emailVerified\n" +
                           "        username\n" +
                           "        nickname\n" +
                           "        company\n" +
                           "        photo\n" +
                           "        browser\n" +
                           "        registerInClient\n" +
                           "        registerMethod\n" +
                           "        oauth\n" +
                           "        token\n" +
                           "        tokenExpiredAt\n" +
                           "        loginsCount\n" +
                           "        lastLogin\n" +
                           "        lastIP\n" +
                           "        signedUp\n" +
                           "        blocked\n" +
                           "        isDeleted\n" +
                           "    }\n" +
                           "}";
            string password = (string)option.GetBykey("password");

            try
            {
                password = RSAHelper.EncryptWithPublicKey(publicKey, Encoding.UTF8.GetBytes(password));
                option.UpdateValue("password", password);
            }
            catch (Exception ex)
            {
                throw new AuthingException("encrypt password fail", ex);
            }
            PostEntity postEntity = new PostEntity(query, option);
            Dictionary <HttpRequestHeader, string> headers = new Dictionary <HttpRequestHeader, string>();

            headers.Add(HttpRequestHeader.Authorization, "Bearer " + ownerToken); //"Authorization"
            string resJson = HttpClientHelper.DoPost(usersUrl, postEntity, headers);

            return(resJson);
        }
예제 #4
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        protected internal string Login(Option option)
        {
            option.CheckByKeys(new string[] { "registerInClient", "email", "password" });
            string query = "mutation login($unionid: String, $email: String, $password: String, $lastIP: String, $registerInClient: String!, $verifyCode: String) {\n" +
                           "    login(unionid: $unionid, email: $email, password: $password, lastIP: $lastIP, registerInClient: $registerInClient, verifyCode: $verifyCode) {\n" +
                           "        _id\n" +
                           "        email\n" +
                           "        emailVerified\n" +
                           "        username\n" +
                           "        nickname\n" +
                           "        company\n" +
                           "        photo\n" +
                           "        browser\n" +
                           "        token\n" +
                           "        tokenExpiredAt\n" +
                           "        loginsCount\n" +
                           "        lastLogin\n" +
                           "        lastIP\n" +
                           "        signedUp\n" +
                           "        blocked\n" +
                           "        isDeleted\n" +
                           "    }\n" +
                           "}";
            string password = (string)option.GetBykey("password");

            try
            {
                password = RSAHelper.EncryptWithPublicKey(publicKey, Encoding.UTF8.GetBytes(password));
                option.UpdateValue("password", password);
            }
            catch (Exception ex)
            {
                throw new AuthingException("encrypt password fail", ex);
            }
            PostEntity postEntity = new PostEntity(query, option);
            string     resJson    = HttpClientHelper.DoPost(usersUrl, postEntity, null);
            var        jobj       = JObject.Parse(resJson);

            if (jobj["data"] != null && jobj["data"]["login"] != null)
            {
                userToken = jobj["data"]["login"]["token"].ToString();
            }
            return(resJson);
        }
예제 #5
0
        /// <summary>
        /// 获取访问Token
        /// </summary>
        /// <returns></returns>
        protected internal string GetAccessTokenByAppSecret()
        {
            if (ownerToken == null || ownerToken == "")
            {
                string query = " query getAccessTokenByAppSecret($id: String!, $secret: String!) { getAccessTokenByAppSecret(secret: $secret,clientId: $id) } ";
                Dictionary <string, object> variables = new Dictionary <string, object>();
                variables.Add("secret", this.appSecret);
                variables.Add("id", this.clientId);

                PostEntity postEntity = new PostEntity(query, variables);
                string     result     = HttpClientHelper.DoPost(usersUrl, postEntity, null);
                var        jobj       = JObject.Parse(result);
                if (jobj["data"] == null || jobj["data"]["getAccessTokenByAppSecret"] == null)
                {
                    throw new AuthingException("wrong clientId or secret");
                }
                this.ownerToken = jobj["data"]["getAccessTokenByAppSecret"].ToString();
            }
            return(ownerToken);
        }
예제 #6
0
        /// <summary>
        /// 批量删除用户
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        protected internal string RemoveUsers(Option option)
        {
            if (ownerToken == "" || ownerToken == null)
            {
                throw new AuthingException("can not find ownerToken,please login again");
            }
            option.CheckByKeys(new string[] { "ids", "registerInClient" });
            string query = "mutation removeUsers($ids: [String], $registerInClient: String, $operator: String){\n" +
                           "  removeUsers(ids: $ids, registerInClient: $registerInClient, operator: $operator) {\n" +
                           "    _id\n" +
                           "  }\n" +
                           "}";
            PostEntity postEntity = new PostEntity(query, option);
            Dictionary <HttpRequestHeader, string> headers = new Dictionary <HttpRequestHeader, string>();

            headers.Add(HttpRequestHeader.Authorization, "Bearer " + ownerToken); //"Authorization"
            string resJson = HttpClientHelper.DoPost(usersUrl, postEntity, headers);

            return(resJson);
        }
예제 #7
0
        /// <summary>
        /// 读取在Authing控制台中配置的OAuth信息
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        protected internal string ReadOAuthList(Option option)
        {
            option.CheckByKey("clientId");
            string query = "  query ReadOAuthList($clientId: String!) {\n" +
                           "        ReadOauthList(clientId: $clientId) {\n" +
                           "            _id\n" +
                           "            name\n" +
                           "            image\n" +
                           "            description\n" +
                           "            enabled\n" +
                           "            client\n" +
                           "            user\n" +
                           "            url\n" +
                           "        }\n" +
                           "    }";
            PostEntity postEntity = new PostEntity(query, option);
            string     resJson    = HttpClientHelper.DoPost(oathUrl, postEntity, null);

            return(resJson);
        }
예제 #8
0
        /// <summary>
        /// 检查登录状态
        /// </summary>
        /// <returns></returns>
        protected internal string CheckLoginStatus()
        {
            if (userToken == "" || userToken == null)
            {
                throw new AuthingException("can not find ownerToken,please login again");
            }
            string query = "query checkLoginStatus {\n" +
                           "    checkLoginStatus {\n" +
                           "        status\n" +
                           "        code\n" +
                           "        message\n" +
                           "    }\n" +
                           "}";
            PostEntity postEntity = new PostEntity(query, new Option());
            Dictionary <HttpRequestHeader, string> headers = new Dictionary <HttpRequestHeader, string>();

            headers.Add(HttpRequestHeader.Authorization, "Bearer " + userToken); //"Authorization"
            string resJson = HttpClientHelper.DoPost(usersUrl, postEntity, headers);

            return(resJson);
        }
예제 #9
0
        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        protected internal string Register(Option option)
        {
            option.CheckByKeys(new string[] { "registerInClient", "email", "password" });
            string query = "  mutation register(\n" +
                           "    $unionid: String,\n" +
                           "    $email: String, \n" +
                           "    $password: String, \n" +
                           "    $lastIP: String, \n" +
                           "    $forceLogin: Boolean,\n" +
                           "    $registerInClient: String!,\n" +
                           "    $oauth: String,\n" +
                           "    $username: String,\n" +
                           "    $nickname: String,\n" +
                           "    $registerMethod: String,\n" +
                           "    $photo: String\n" +
                           ") {\n" +
                           "    register(userInfo: {\n" +
                           "        unionid: $unionid,\n" +
                           "        email: $email,\n" +
                           "        password: $password,\n" +
                           "        lastIP: $lastIP,\n" +
                           "        forceLogin: $forceLogin,\n" +
                           "        registerInClient: $registerInClient,\n" +
                           "        oauth: $oauth,\n" +
                           "        registerMethod: $registerMethod,\n" +
                           "        photo: $photo,\n" +
                           "        username: $username,\n" +
                           "        nickname: $nickname\n" +
                           "    }) {\n" +
                           "        _id,\n" +
                           "        email,\n" +
                           "        emailVerified,\n" +
                           "        username,\n" +
                           "        nickname,\n" +
                           "        company,\n" +
                           "        photo,\n" +
                           "        browser,\n" +
                           "        password,\n" +
                           "        token,\n" +
                           "        group {\n" +
                           "            name\n" +
                           "        },\n" +
                           "        blocked\n" +
                           "    }\n" +
                           "}";
            string password = (string)option.GetBykey("password");

            try
            {
                password = RSAHelper.EncryptWithPublicKey(publicKey, Encoding.UTF8.GetBytes(password));
                option.UpdateValue("password", password);
            }
            catch (Exception ex)
            {
                throw new AuthingException("encrypt password fail", ex);
            }
            PostEntity postField = new PostEntity(query, option);
            string     resJson   = HttpClientHelper.DoPost(usersUrl, postField, null);

            return(resJson);
        }
예제 #10
0
        /// <summary>
        /// 更新用户信息
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        protected internal string UpdateUser(Option option)
        {
            if (ownerToken == "" || ownerToken == null)
            {
                throw new AuthingException("can not find ownerToken,please login again");
            }
            option.CheckByKeys(new string[] { "_id", "registerInClient" });
            string query = "mutation UpdateUser(\n" +
                           "    _id: String!,\n" +
                           "   email: String,\n" +
                           "   emailVerified: Boolean,\n" +
                           "   username: String,\n" +
                           "   nickname: String,\n" +
                           "   company: String,\n" +
                           "   photo: String,\n" +
                           "   browser: String,\n" +
                           "   password: String,\n" +
                           "   oldPassword: String,\n" +
                           "   registerInClient: String!,\n" +
                           "   token: String,\n" +
                           "   tokenExpiredAt: String,\n" +
                           "   loginsCount: Int,\n" +
                           "   lastLogin: String,\n" +
                           "   lastIP: String,\n" +
                           "   signedUp: String,\n" +
                           "   blocked: Boolean,\n" +
                           "   isDeleted: Boolean\n" +
                           "   ){\n" +
                           "    updateUser(options: {\n" +
                           "     _id: $_id,\n" +
                           "    email: $email,\n" +
                           "    emailVerified: $emailVerified,\n" +
                           "    username: $username,\n" +
                           "    nickname: $nickname,\n" +
                           "    company: $company,\n" +
                           "    photo: $photo,\n" +
                           "    browser: $browser,\n" +
                           "    password: $password,\n" +
                           "    oldPassword: $oldPassword,\n" +
                           "    registerInClient: $registerInClient,\n" +
                           "    token: $token,\n" +
                           "    tokenExpiredAt: $tokenExpiredAt,\n" +
                           "    loginsCount: $loginsCount,\n" +
                           "    lastLogin: $lastLogin,\n" +
                           "    lastIP: $lastIP,\n" +
                           "    signedUp: $signedUp,\n" +
                           "    blocked: $blocked,\n" +
                           "    isDeleted: $isDeleted\n" +
                           "    }) {\n" +
                           "    _id\n" +
                           "    email\n" +
                           "    emailVerified\n" +
                           "    username\n" +
                           "    nickname\n" +
                           "    company\n" +
                           "    photo\n" +
                           "    browser\n" +
                           "    registerInClient\n" +
                           "    registerMethod\n" +
                           "    oauth\n" +
                           "    token\n" +
                           "    tokenExpiredAt\n" +
                           "    loginsCount\n" +
                           "    lastLogin\n" +
                           "    lastIP\n" +
                           "    signedUp\n" +
                           "    blocked\n" +
                           "    isDeleted\n" +
                           "    }\n" +
                           "}";
            PostEntity postEntity = new PostEntity(query, option);
            Dictionary <HttpRequestHeader, string> headers = new Dictionary <HttpRequestHeader, string>();

            headers.Add(HttpRequestHeader.Authorization, "Bearer " + ownerToken); //"Authorization"
            string resJson = HttpClientHelper.DoPost(usersUrl, postEntity, headers);

            return(resJson);
        }
예제 #11
0
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        protected internal string Users(Option option)
        {
            option.CheckByKeys(new string[] { "registerInClient", "page", "count" });
            string query = "query users($registerInClient: String, $page: Int, $count: Int){\n" +
                           "  users(registerInClient: $registerInClient, page: $page, count: $count) {\n" +
                           "    totalCount\n" +
                           "    list {\n" +
                           "      _id\n" +
                           "      email\n" +
                           "      emailVerified\n" +
                           "      username\n" +
                           "      nickname\n" +
                           "      company\n" +
                           "      photo\n" +
                           "      browser\n" +
                           "      password\n" +
                           "      registerInClient\n" +
                           "      token\n" +
                           "      tokenExpiredAt\n" +
                           "      loginsCount\n" +
                           "      lastLogin\n" +
                           "      lastIP\n" +
                           "      signedUp\n" +
                           "      blocked\n" +
                           "      isDeleted\n" +
                           "      group {\n" +
                           "        _id\n" +
                           "        name\n" +
                           "        descriptions\n" +
                           "        createdAt\n" +
                           "      }\n" +
                           "      clientType {\n" +
                           "        _id\n" +
                           "        name\n" +
                           "        description\n" +
                           "        image\n" +
                           "        example\n" +
                           "      }\n" +
                           "      userLocation {\n" +
                           "        _id\n" +
                           "        when\n" +
                           "        where\n" +
                           "      }\n" +
                           "      userLoginHistory {\n" +
                           "        totalCount\n" +
                           "        list{\n" +
                           "          _id\n" +
                           "          when\n" +
                           "          success\n" +
                           "          ip\n" +
                           "          result\n" +
                           "        }\n" +
                           "      }\n" +
                           "      systemApplicationType {\n" +
                           "        _id\n" +
                           "        name\n" +
                           "        descriptions\n" +
                           "        price\n" +
                           "      }\n" +
                           "    }\n" +
                           "  }\n" +
                           "}";
            PostEntity postEntity = new PostEntity(query, option);
            Dictionary <HttpRequestHeader, string> headers = new Dictionary <HttpRequestHeader, string>();

            headers.Add(HttpRequestHeader.Authorization, "Bearer " + ownerToken); //"Authorization"
            string resJson = HttpClientHelper.DoPost(usersUrl, postEntity, headers);

            return(resJson);
        }