public static async Task <ODConnection> Login(string account, string code) { if (string.IsNullOrEmpty(account)) { throw new ArgumentNullException(nameof(account)); } string refreshToken = LoadRefreshToken(account); AppTokenResponse response = null; if (!string.IsNullOrEmpty(refreshToken)) { response = await RedeemRefreshTokenAsync(Secrets.CLIENT_ID, Secrets.CLIENT_SECRET, refreshToken); } if (response == null) { if (string.IsNullOrEmpty(code)) { var authenticationUri = GetAuthenticationUri(Secrets.CLIENT_ID); code = GetAuthCode(account, authenticationUri, new Uri(LIVE_LOGIN_DESKTOP_URI))?.TrimStart('M'); if (string.IsNullOrEmpty(code)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.RetrieveAuthenticationCodeFromUri, authenticationUri.ToString())); } } response = await RedeemAccessTokenAsync(Secrets.CLIENT_ID, Secrets.CLIENT_SECRET, code); } SaveRefreshToken(account, response != null ? response.RefreshToken : null); return(response != null ? new ODConnection(ONEDRIVE_API_URI, response.AccessToken) : null); }
public static async Task <Client> LoginAsync(string account, string code, string settingsPassPhrase) { if (string.IsNullOrEmpty(account)) { throw new ArgumentNullException(nameof(account)); } var refreshToken = LoadRefreshToken(account, settingsPassPhrase); AppTokenResponse response = null; if (!string.IsNullOrEmpty(refreshToken)) { response = await RedeemRefreshTokenAsync(Secrets.CLIENT_ID, Secrets.CLIENT_SECRET, refreshToken); } if (response == null) { if (string.IsNullOrEmpty(code)) { var authenticationUri = GetAuthenticationUri(Secrets.CLIENT_ID); code = GetAuthCode(account, authenticationUri, new Uri(HUBIC_LOGIN_REDIRECT_URI)); if (string.IsNullOrEmpty(code)) { throw new AuthenticationException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.RetrieveAuthenticationCodeFromUri, authenticationUri.ToString())); } } response = await RedeemAccessTokenAsync(Secrets.CLIENT_ID, Secrets.CLIENT_SECRET, code); if (response == null) { throw new AuthenticationException(); } } SaveRefreshToken(account, response.RefreshToken ?? refreshToken, settingsPassPhrase); var authManager = new SwiftAuthManager() { Credentials = new SwiftCredentials() { Password = response.AccessToken }, Authenticate = (user, password, endpoint) => AuthenticateAsync(password) }; authManager.SetEndpoints(new[] { "http://localhost:8080" }.ToList()); return(new Client(authManager)); }
public async Task <HttpResponseMessage> Register(RegistrationAddRequest model) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, string.Join(", ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage)))); } try { if (model.DateOfBirth <= DateTime.MinValue) { throw new ArgumentException("Please Select your Date of Birth"); } IdentityUser user = _userService.CreateUser(model.Email, model.Password); if (user != null) { RegistrationResponse response = new RegistrationResponse(); response.AspNetUserID = user.Id; response.Email = model.Email; response.MemberProfileId = _memberProfileService.Insert(new MemberProfileAddRequest { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Gender = model.Gender, DateOfBirth = model.DateOfBirth, AspNetUserID = user.Id, IsActive = true, IsPublic = true, IsViewable = true }); if (response.MemberProfileId > 0) { try { AppTokenResponse tokenResponse = new AppTokenResponse(); AppTokenAddRequest tokenObject = new AppTokenAddRequest() { MemberProfileId = response.MemberProfileId, TokenTypeId = (int)AppTokenType.ConfirmRegistration }; tokenResponse.TokenGuid = _appTokenService.Insert(tokenObject); await _sendEmailService.SendEmailRegConfirm(response.Email, tokenResponse.TokenGuid); return(Request.CreateResponse(HttpStatusCode.OK, response)); } catch { throw; } } } return(Request.CreateResponse(HttpStatusCode.OK, "Registration Success")); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }