public async Task <IActionResult> FinishAuth(GatewayUser user, FinishAuthInfo model, bool forceGrant, bool trusted) { var authorized = await HasAuthorizedApp(user, model.AppId); if (!authorized && trusted) { // Unauthorized. But viewing a trusted app. Just auto auth him. await GrantTargetApp(user, model.AppId); authorized = true; } if (authorized && forceGrant != true) { // Dont need to auth, and the user don't force to auth. var pack = await GeneratePack(user, model.AppId); var url = new AiurUrl(GetRegexRedirectUri(model.RedirectUri), new AuthResultAddressModel { Code = pack.Code, State = model.State }); return(new RedirectResult(url.ToString())); } else { // Need to do the auth logic. var url = new AiurUrl(string.Empty, "OAuth", nameof(OAuthController.AuthorizeConfirm), new FinishAuthInfo { AppId = model.AppId, RedirectUri = model.RedirectUri, State = model.State }); return(new RedirectResult(url.ToString())); } }
public async Task <IActionResult> AuthorizeConfirm(FinishAuthInfo model) { if (!ModelState.IsValid) { return(View("AuthError")); } var app = (await _apiService.AppInfoAsync(model.AppId)).App; var user = await GetCurrentUserAsync(); var viewModel = new AuthorizeConfirmViewModel { AppName = app.AppName, UserNickName = user.NickName, AppId = model.AppId, RedirectUri = model.RedirectUri, FailBackUrl = app.AppFailCallbackUrl, State = model.State, // Permissions ViewOpenId = app.ViewOpenId, ViewPhoneNumber = app.ViewPhoneNumber, ChangePhoneNumber = app.ChangePhoneNumber, ConfirmEmail = app.ConfirmEmail, ChangeBasicInfo = app.ChangeBasicInfo, ChangePassword = app.ChangePassword, ChangeGrantInfo = app.ChangeGrantInfo, ViewAuditLog = app.ViewAuditLog, TermsUrl = app.LicenseUrl, PStatementUrl = app.PrivacyStatementUrl, ManageSocialAccount = app.ManageSocialAccount }; return(View(viewModel)); }
public IActionResult RecoveryCodeAuth(FinishAuthInfo model) { if (!ModelState.IsValid) { return(View("AuthError")); } var viewModel = new RecoveryCodeAuthViewModel { AppId = model.AppId, RedirectUri = model.RedirectUri, State = model.State }; return(View(viewModel)); }
public async Task <IActionResult> FinishAuth(GatewayUser user, FinishAuthInfo model, bool forceGrant) { if (await HasAuthorizedApp(user, model.AppId) && forceGrant == false) { var pack = await GeneratePack(user, model.AppId); var url = new AiurUrl(GetRegexRedirectUri(model.RedirectUri), new AuthResultAddressModel { Code = pack.Code, State = model.State }); return(new RedirectResult(url.ToString())); } else { var url = new AiurUrl("", "OAuth", nameof(OAuthController.AuthorizeConfirm), new FinishAuthInfo { AppId = model.AppId, RedirectUri = model.RedirectUri, State = model.State }); return(new RedirectResult(url.ToString())); } }