/// <summary> /// Send username and password authorisation /// supports only AUTH=PLAIN for now /// </summary> /// <param name="user">email account username</param> /// <param name="pass">email account password</param> /// <param name="authType">Authorisation type to use</param> public void SendAuthUserPass(String user, String pass, AuthTypes authType = AuthTypes.Plain) { string response = ""; if (authType == AuthTypes.Plain) { Write(". AUTHENTICATE PLAIN"); response = Response(); if (!response.StartsWith("+")) { throw new Imap4Exception(response); } byte[] authBytes = { 0 }; authBytes = authBytes.Concat(Encoding.ASCII.GetBytes(user)).Concat(new byte[] { 0 }).Concat(Encoding.ASCII.GetBytes(pass)).ToArray(); Write(Convert.ToBase64String(authBytes)); response = Response(); } while (!response.StartsWith(".")) { response = Response(); } if (response.Substring(0, 4) != ". OK") { throw new Imap4Exception(response); } }
internal void InvokeLink(AuthTypes linkType, PlayFabError error = null) { if (OnPlayFabLink != null) { OnPlayFabLink.Invoke(linkType, error); } }
internal void InvokeUnlink(AuthTypes unlinkType, PlayFabError error = null) { if (OnPlayFabUnlink != null) { OnPlayFabUnlink.Invoke(unlinkType, error); } }
public User(int id, string name, string description, bool loggedIn, AuthTypes authType, int loginFailedCount, string password) { Id = id; Name = name; Description = description; LoggedIn = loggedIn; AuthType = authType; LoginFailedCount = loginFailedCount; Password = password; }
public HeadBarViewModel() { _breadcrumbBarViewModel = new BreadcrumbBarViewModel(); _userName = "******"; _role = AuthTypes.Other; var dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += DateTimeUpdater; dispatcherTimer.Interval = TimeSpan.FromSeconds(1); dispatcherTimer.Start(); }
protected override void HandleAssembly(Assembly assembly) { assembly.GetTypes() .Where(type => !type.IsInterface) .Where(type => !type.IsAbstract) .Where(type => BaseParameterType.IsAssignableFrom(type)) .ToList() .ForEach(type => { var result = HandleType(type); AuthTypes.AddOrUpdate(type, result, (t, b) => result); }); }
/// <summary> /// OAuth2 客戶端,使用 Client Credential 認證 /// </summary> /// <param name="clientId">Client Id</param> /// <param name="clientSecret">Client Secret</param> /// <param name="baseUri">OAuth2 Server 網址, 範例 http://{root}/oauth2/</param> public OAuth2Client(Uri baseUri, string clientId, string clientSecret) { _authType = AuthTypes.ClientCredential; _baseUri = baseUri; _clientId = clientId; _clientSecret = clientSecret; _httpClient = new HttpClient { BaseAddress = _baseUri }; // We want the response to be JSON. _httpClient.DefaultRequestHeaders.Accept.Clear(); _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }
protected static string GetAuthType(AuthTypes authType) { switch (authType) { case AuthTypes.PIN: return("PIN"); case AuthTypes.VBVSECURECODE: return("VBVSECURECODE"); case AuthTypes.AVS_VBVSECURECODE: return("AVS_VBVSECURECODE"); default: return("PIN"); } }
/// <summary> /// Add Authorization header to the <see cref="HttpRequest" /> /// </summary> /// <param name="parameter">The parameter for the request</param> /// <param name="request">The http request</param> public async Task HandleRequest(HttpParameter parameter, HttpRequest request) { try { var requireAuth = AuthTypes.GetOrAdd(parameter.GetType(), HandleType); if (requireAuth) { var accessToken = await AuthorizationService.GetAccessToken(); request.AddHeader("Authorization", $"Bearer {accessToken}"); } } catch (Exception e) { Error(e); } }
protected async Task Auth(string code = null, List <ShyftConstants.AuthScopes> scopes = null) { JObject authData; if (string.IsNullOrEmpty(code)) { authData = JObject.FromObject(new { grant_type = "client_credentials" }); if (scopes == null || scopes.Count == 0) { authData["scope"] = "public"; } else { authData["scope"] = GetScopesString(scopes); } AuthType = AuthTypes.TwoLeg; } else { authData = JObject.FromObject(new { grant_type = "authorization_code", code = code }); AuthType = AuthTypes.ThreeLeg; } httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", GetBasicAuth()); JObject responseObject = await PostLyftAuth(new Url(ShyftConstants.BaseUrl).AppendPathSegments("oauth", "token"), authData); ExpiresAt = DateTime.Now + TimeSpan.FromSeconds((int)responseObject["expires_in"]); AccessToken = (string)responseObject["access_token"]; httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken); if (AuthType == AuthTypes.ThreeLeg) { RefreshToken = (string)responseObject["refresh_token"]; } }
public ServerAuthenticator(NetServer netServer, string serverName, string serverDescription, AuthTypes authType) { this.netServer = netServer; this.serverName = serverName; this.serverDescription = serverDescription; this.authType = authType; this.credentialStore = new CredentialStore(); this.sessions = new Dictionary <string, Session>(); this.sessionCleanupTimer = new Timer { Interval = 10000.00, // 10 seconds AutoReset = true }; this.sessionCleanupTimer.Elapsed += onSessionCleanup; this.sessionCleanupTimer.Start(); netServer.RegisterPacketHandler(MODULE_NAME, packetHandler); netServer.OnConnectionEstablished += ConnectionEstablishedHandler; netServer.OnConnectionClosed += ConnectionClosedHandler; }
public override void OnAuthorization(HttpActionContext actionContext) { if (actionContext.RequestContext.Principal.Identity.IsAuthenticated) { bool result = AuthorizeRequest(actionContext); if (result) { return; } else { authType = AuthTypes.Authorize; HandleUnauthorizedRequest(actionContext); } } else { authType = AuthTypes.Authenticate; HandleUnauthorizedRequest(actionContext); } }
/// <summary> /// OAuth2 客戶端,使用 Authorization Code認證 /// </summary> /// <param name="clientId">Client Id</param> /// <param name="clientSecret">Client Secret</param> /// <param name="userName">水文開放資料平台帳號</param> /// <param name="password">水文開放資料平台密碼</param> /// <param name="baseUri">OAuth2 Server 網址, 範例 http://{root}/oauth2/ </param> public OAuth2Client(Uri baseUri, Uri redirectUri, string clientId, string clientSecret, string userName, string password) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; if (!baseUri.AbsoluteUri.StartsWith("https")) { throw new Exception("Only support https protocol"); } _authType = AuthTypes.AuthorizationCode; _baseUri = baseUri; _clientId = clientId; _clientSecret = clientSecret; _redirectUri = redirectUri; _password = password; _userName = userName; _httpClient = new HttpClient(); _httpClient.BaseAddress = _baseUri; //http://{root}/oauth2/ // We want the response to be JSON. _httpClient.DefaultRequestHeaders.Accept.Clear(); _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }
public Host() { AuthType = AuthTypes.WINDOWS; Databases = new List <string>(); }
public ServerAuthenticator(NetServer netServer, string serverName, string serverDescription, AuthTypes authType, string credentialStorePath) : this(netServer, serverName, serverDescription, authType) { Load(credentialStorePath); }
public AuthToken(string username, AuthTypes authType, DateTimeOffset expires) { this.Username = username; this.AuthType = authType; this.Expire = (DateTime.UtcNow.AddTicks(expires.Ticks)).Ticks; }
/// <summary> /// Create auth filter with custom authentication type and roles. Use this constructor /// for global filter registration /// </summary> /// <param name="expectedAuthScheme"></param> /// <param name="roles"></param> public AuthFilter(AuthTypes expectedAuthScheme, params string[] roles) :base() { this.roles = roles; this.expectedAuthScheme = expectedAuthScheme; }
public async Task AuthWithRefreshToken(string refreshToken) { AuthType = AuthTypes.ThreeLeg; RefreshToken = refreshToken; await RefreshAccessToken(); }
public void SetType(AuthTypes k) { auth = k; }
public NetworkCredential GetCredential(Uri uri, string authType) { return(authType == null || !AuthTypes.Any() || AuthTypes.Any(x => StringComparer.OrdinalIgnoreCase.Equals(x, authType)) ? InnerCredential.GetCredential(uri, authType) : null); }
/// <summary> /// Kick off the authentication process by specific authType. /// </summary> /// <param name="authType"></param> /// <param name="authKeys"></param> public void Authenticate(AuthTypes authType, AuthKeys authKeys = null) { AuthType = authType; Authenticate(authKeys); }
/// <summary> /// Send the Authentication challenge request /// </summary> /// <param name="message"></param> /// <param name="actionContext"></param> private void challenge(HttpActionContext actionContext, string message, AuthTypes scheme) { var body = new { error = message }; actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized, body); actionContext.Response.Headers.Add("WWW-Authenticate", scheme.ToString()); }
public static bool DoSocksAuth(Socks5Client p, string Username, string Password) { AuthTypes auth = Socks.Greet(p.Client); if (auth == AuthTypes.Unsupported) { p.Client.Disconnect(); return(false); } if (auth != AuthTypes.None) { p.enc = new Encryption.SocksEncryption(); switch (auth) { case AuthTypes.Login: //logged in. p.enc.SetType(AuthTypes.Login); //just reqeust login? break; case AuthTypes.SocksBoth: //socksboth. p.enc.SetType(AuthTypes.SocksBoth); p.enc.GenerateKeys(); //send public key. p.Client.Send(p.enc.GetPublicKey()); //now receive key. byte[] buffer = new byte[4096]; int keysize = p.Client.Receive(buffer, 0, buffer.Length); p.enc.SetKey(buffer, 0, keysize); //let them know we got it //now receive our encryption key. int enckeysize = p.Client.Receive(buffer, 0, buffer.Length); //decrypt with our public key. byte[] newkey = new byte[enckeysize]; Buffer.BlockCopy(buffer, 0, newkey, 0, enckeysize); p.enc.SetEncKey(p.enc.key.Decrypt(newkey, false)); //now we share our encryption key. p.Client.Send(p.enc.ShareEncryptionKey()); break; case AuthTypes.SocksEncrypt: p.enc.SetType(AuthTypes.SocksEncrypt); p.enc.GenerateKeys(); //send public key. p.Client.Send(p.enc.GetPublicKey()); //now receive key. buffer = new byte[4096]; keysize = p.Client.Receive(buffer, 0, buffer.Length); p.enc.SetKey(buffer, 0, keysize); //let them know we got it p.Client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)HeaderTypes.Zero }); //now receive our encryption key. enckeysize = p.Client.Receive(buffer, 0, buffer.Length); //decrypt with our public key. newkey = new byte[enckeysize]; Buffer.BlockCopy(buffer, 0, newkey, 0, enckeysize); p.enc.SetEncKey(p.enc.key.Decrypt(newkey, false)); //wait for server to confirm we got it. p.Client.Receive(buffer, 0, buffer.Length); //now we share our encryption key. p.Client.Send(p.enc.ShareEncryptionKey()); //socksencrypt. break; case AuthTypes.SocksCompress: p.enc.SetType(AuthTypes.SocksCompress); //sockscompress. break; default: p.Client.Disconnect(); return(false); } if (p.enc.GetAuthType() != AuthTypes.Login) { //now receive login params. byte[] buff = new byte[1024]; int recv = p.Client.Receive(buff, 0, buff.Length); //check for if (recv > 0) { //check if socks5 version is 5 if (buff[0] == 0x05) { //good. if (buff[1] == (byte)AuthTypes.Login) { if (Username == null || Password == null) { p.Client.Sock.Close(); return(false); } int ret = Socks.SendLogin(p.Client, Username, Password); if (ret != 1) { p.Client.Sock.Close(); return(false); } } else { //idk? close for now. p.Client.Disconnect(); return(false); } } } else { p.Client.Disconnect(); return(false); } } else { if (Username == null || Password == null) { p.Client.Sock.Close(); return(false); } int ret = Socks.SendLogin(p.Client, Username, Password); if (ret != 1) { p.Client.Sock.Close(); return(false); } } } return(true); }
public Host() { AuthType = AuthTypes.Windows; Databases = new List <string>(); }