public async Task <ActionResult> Authorize(MobileConnectAuthorizeModel model) { if (string.IsNullOrEmpty(model.PhoneNumber) || string.IsNullOrEmpty(model.RedirectUrl) || string.IsNullOrEmpty(model.NotificationUri) || string.IsNullOrEmpty(model.DiscoveryUrl) || string.IsNullOrEmpty(model.DiscoveryClientId) || string.IsNullOrEmpty(model.DiscoveryPassword) || string.IsNullOrEmpty(model.PrivateRsaKeyPath)) { return(Content("Fill all fields")); } var authorizeSettings = new MobileConnectSiAuthorizeSettings { PhoneNumber = model.PhoneNumber, RedirectUrl = model.RedirectUrl, NotificationUri = model.NotificationUri, DiscoveryUrl = model.DiscoveryUrl, DiscoveryClientId = model.DiscoveryClientId, DiscoveryPassword = model.DiscoveryPassword, PrivateRsaKeyPath = model.PrivateRsaKeyPath }; var authorizeResult = await _mobileConnectService.SiAuthorize(authorizeSettings); if (!authorizeResult.IsSucceeded) { MobileConnectAuthorizeLogger.Warn( $"Authorize [authReqId: {authorizeResult.AuthReqId}, correlationId: {authorizeResult.CorrelationId}]. authorizeResult is not succeeded"); MobileConnectAuthorizeLogger.Warn(authorizeResult.ToString()); } var mobileConnectRequest = new MobileConnectAuthorizeRequest { PhoneNumber = model.PhoneNumber, ClientNotificationToken = authorizeResult.ClientNotificationToken, AuthReqId = authorizeResult.AuthReqId, CorrelationId = authorizeResult.CorrelationId, Nonce = authorizeResult.Nonce, IsResponseSucceeded = authorizeResult.IsSucceeded, ResponseErrorMessage = authorizeResult.ErrorMessage, RequestedDateTime = DateTime.Now }; _repository.CreateMobileConnectAuthorizeRequest(mobileConnectRequest); return(PartialView("_MobileConnectAuthorizePartial", authorizeResult)); }
private void ValidateTokens(MobileConnectNotifyModel notifyModel, MobileConnectAuthorizeRequest mobileConnectRequest, out string errorMessage) { var idTokenClaims = notifyModel.IdToken.GetJwtTokenClaims(); var nonce = idTokenClaims.FirstOrDefault(x => x.Type == "nonce"); if (nonce?.Value != mobileConnectRequest.Nonce) { errorMessage = "id_token nonce is null or invalid"; return; } var accessTokenClaims = notifyModel.AccessToken.GetJwtTokenClaims(); var sub = accessTokenClaims.FirstOrDefault(x => x.Type == "sub"); if (sub?.Value != mobileConnectRequest.PhoneNumber) { errorMessage = "access_token sub is null or invalid"; return; } errorMessage = ""; }
public void CreateMobileConnectAuthorizeRequest(MobileConnectAuthorizeRequest mobileConnectRequest) { InMemoryDatabase.MobileConnectAuthorizeRequests.Add(mobileConnectRequest); }