public IEnumerable <File> Get() { var service = _authenticationHelper.Authenticate(); var fileHandler = new FileHandler(service); var files = fileHandler.FetchFiles("mimeType='audio/mpeg'"); return(files); }
public IActionResult Post([FromBody] UserCredentialsForm user) { var userResult = _authenticationHelper.Authenticate(user.Email.ToUnescapeDataString(), user.Password.ToUnescapeDataString()); if (userResult is null) { return(Ok(new ErrorResult { Error = "Invalid user or credentials" })); } return(Ok(userResult)); }
// GET: api/Auth public HttpResponseMessage Get(string application = null) { //if not basic Authorization punt if (Request.Headers.Authorization == null || Request.Headers.Authorization.Scheme != "Basic") { throw new HttpResponseException(Request.CreateErrorResponse(System.Net.HttpStatusCode.Unauthorized, "You are unauthorized.")); } //authenticate var userNameAndPasword = ExtractUserNameAndPassword(Request.Headers.Authorization.Parameter); var username = userNameAndPasword.Item1; if (userNameAndPasword == null || !_authenticationHelper.Authenticate(userNameAndPasword.Item1, userNameAndPasword.Item2)) { throw new HttpResponseException(Request.CreateErrorResponse(System.Net.HttpStatusCode.Unauthorized, "You are unauthorized.")); } //assume application is username if not specified application = application ?? username; //get certificate var certAndKeyInfo = CertHelper.GetCertAndKeyInfoFromDisk(_authenticationServerConfiguration.AuthCertificatesRoot, DEFAULT_CERTIFICATE_NAME, true); //create signing credentials using the resolved certificate var x509SigningCredentials = new X509SigningCredentials(certAndKeyInfo.Certificate); //create token var jwtSecurityToken = new JwtSecurityToken( issuer: "mycompanyauth", audience: "mycompany", claims: new List <Claim>() { new Claim(ClaimTypes.Name, username), //new Claim(ClaimTypes.Role, "AdminRole"), //new Claim(ClaimTypes.UserData, userData) }, notBefore: DateTime.UtcNow.AddMinutes(_authenticationServerConfiguration.AuthTokenNotBeforeAdjustMinutes), expires: DateTime.UtcNow.AddMinutes(_authenticationServerConfiguration.AuthTokenExpiryMinutes), signingCredentials: x509SigningCredentials ); //create a token handler and use it to write the token to a string var tokenHandler = new JwtSecurityTokenHandler(); string tokenString = tokenHandler.WriteToken(jwtSecurityToken); //respond return(new HttpResponseMessage() { Content = new StringContent(tokenString, Encoding.UTF8, "text/html") }); }
private async void Authenticate(MobileServiceAuthenticationProvider provider) { if (TechReady.Helpers.NetworkHelper.NetworkHelper.IsNetworkAvailable() == false) { await MessageHelper.ShowMessage(CommonSettings.LoginNoNetworkMessage); return; } try { this.ViewModel.OperationInProgress = true; var userInfo = await authHelper.Authenticate(provider); if (userInfo != null) { var userPageViewModel = new UserRegistrationPageViewModel(); userPageViewModel.FullName = userInfo.Username; userPageViewModel.Email = userInfo.Email; userPageViewModel.AuthProvider = userInfo.AuthProvider; userPageViewModel.AuthProviderUserId = userInfo.AuthProviderUserId; if (await userPageViewModel.GetTechnologes()) { Navigation.PushAsync(new HubPage(null)); //Clear Backstack for (int i = 0; i < this.Navigation.NavigationStack.Count - 1; i++) { this.Navigation.RemovePage(this.Navigation.NavigationStack[i]); } } else { Navigation.PushAsync(new UserRegistrationPage(userPageViewModel)); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } finally { this.ViewModel.OperationInProgress = false; } }