/// <summary> /// 检查oauth2相关参数 /// </summary> /// <param name="client_id"></param> /// <param name="client_secret"></param> /// <param name="grant_type"></param> private void CheckOAuthParam(int client_id, string client_secret, string grant_type) { //检查grant_type if (grant_type != "password") { throw new ApiException("手机端只支持password方式授权", ResultCode.GrantType_Error); } //检查client_id 和client_secret var client = OAuthClientService.GetClientBy(client_id, client_secret); if (client == null) { throw new ApiException("客户端id不存在或者client_secret有误", ResultCode.Client_Error); } }
/// <summary> /// Cleans up any client credentials and access/refresh tokens for all /// users. /// </summary> private void HandleCleanup(HttpListenerContext ctx) { lock (_inprogLock) { if (_inprogressAuthorisations.Count == 0) { OAuthClientService oauthService = new OAuthClientService(); oauthService.ClientId = Settings.ClientId; oauthService.Cleanup(); ctx.Response.Close(); return; } } //if we've gotten this far then we couldnt clean up because there //are auths in progress. SendFailureResponse(ctx, "Cleanup failed, authorisations in progress"); }
private AuthAttempt CreateAndAddInProgressAuthorisation(string username) { lock (_inprogLock) { if (_inprogressAuthorisations.ContainsKey(username)) { return null; } else { OAuthClientService oauthService = new OAuthClientService(Settings.ClientId, username); AuthAttempt attempt = new AuthAttempt() { AuthService = oauthService, Owner = username, StartedAtUtc = DateTime.UtcNow }; _inprogressAuthorisations.Add(username, attempt); return attempt; } } }