i using twilio to send sms verification code when add phone Number to account
and when i debug my app the usermanager.smsSerivice is null while i regesterd it in identitiyconfig here is my code
// Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user
// You can write your own provider and plug it in here.
manager.RegisterTwoFactorProvider("Phone Code", new PhoneNumberTokenProvider<ApplicationUser>
{
MessageFormat = "Your security code is {0}"
});
manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider<ApplicationUser>
{
Subject = "Security Code",
BodyFormat = "Your security code is {0}"
});
manager.EmailService = new EmailService();
manager.SmsService = new SmsService();
var dataProtectionProvider = options.DataProtectionProvider;
if (dataProtectionProvider != null)
{
manager.UserTokenProvider =
new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
}
return manager;
You can call SmsService without a manager like below:
var message = new IdentityMessage
{
Destination = phoneNumber,
Body = "Your verification code is: " + code
};
await new SmsService().SendAsync(message);
Related
i am trying to access my mailbox via ExchangeWebService using OAuth. I followed the instructions based on this page: "https://learn.microsoft.com/de-de/exchange/client-developer/exchange-web-services/how-to-authenticate-an-ews-application-by-using-oauth".
This is my code:
pcaOptions = new PublicClientApplicationOptions()
{
TenantId = "<my tenantID>",
ClientId = "<my ClientID>"
};
pca = PublicClientApplicationBuilder.CreateWithApplicationOptions(pcaOptions).Build();
// The permission scope required for EWS access
ewsScopes = new string[] { "https://outlook.office365.com/EWS.AccessAsUser.All" };
service = new ExchangeService();
// Make the interactive token request
var authResult = await pca.AcquireTokenInteractive(ewsScopes).ExecuteAsync();
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
service.Credentials = new OAuthCredentials(authResult.AccessToken);
Up to this Point, evrything seems allright. The method "AcquireTokenInteractive" opens a ne windows from Microsoft where i can choose my mailaccount from my organization. The variable "authResult" ist filled and contains a new "AccessToken".
The problem starts here:
var folders = await service.FindFolders(WellKnownFolderName.MsgFolderRoot, new FolderView(10));
This method causes an exception:
Das Format des Werts "Bearer eyJ0eXAiOiJKV1Q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TExMzQiLCJwdWlkIjoiMTAwMzIwMDExOUU3OUVDQiIsInJoIjoiMC5BVEVBWVFNb3RiTzkxVW1XVmRRWVRzNHZZd0lBQUFBQUFQRVB6Z0FBQUFBQUFBQXhBQlkuIiwic2NwIjoiRVdTLkFjY2Vzc0FzVXNlci5BbGwiLCJzaWQiOiI5Mzk2NDg1Mi0wMjY3LTRhNjAtOGViNC1lYTVjZWViZmI1MzYiLCJzaWduaW5fc3RhdGUiOlsia21zaSJdLCJzdWIiOiJwdEQwTXhhVFhfektpNUZfcGVTSVFubGZzNDRsMm9EdHBBczZQM2RoZWFBIiwidGlkIjoiYjUyODAzNjEtYmRiMy00OWQ1LTk2NTUtZDQxODRlY2UyZjYzIiwidW5pcXVlX25hbWUiOiJrLmhlaW1lckBiYXNlNGl0LmNvbSIsInVwbiI6ImsuaGVpbWVyQGJhc2U0aXQuY29tIiwidXRpIjoieTJ6bkg0ZTNKVTItdWZ4RGhhdFVBQSIsInZlciI6IjEuMCIsIndpZHMiOlsiYjc5ZmJmNGQtM2VmOS00Njg5LTgxNDMtNzZiMTk0ZTg1NTA5Il19.K6xGoZEMW19JsC-ZSrnUrgF8s8eQv_qwFBZzDELMHnikgZzqDwUEd7_41eAL5hDiKMLTfOfqMrjoVqHViqMic7wyY1QOlx9Kzz6vYTuqMFwYOdevwhEAOgH7uMzCE08c-Wu35UPV_vxWqZfGLLRgJHqTFaUWz0kkdtXk1vLs5MDvWL8CYwXq8gHzM2Mhh8wtB-ZIrjSAHtsrSt43KkBe-cP5PJvqvsyvm4lf-ajKxQtFj0Q4uc8YcCume0suiBgCltxuMcz4uP4OAFgGrbZ04BB33GLDwwFKcR9fs524k2D9kp-0Nf3THDPQYLpraGyPViwfBHdUcDC6BBb40-b0sQ" ist ungültig.
What am i doing wrong?
Greetings, Karsten.
I was following this tutorial: https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-registration-management
So I wrote some test send code looks like:
void TestSend(bool ios)
{
var AzureName = "myhubname";
var AzureHub = new ServiceBusConnectionStringBuilder("Endpoint=sb://secret+sauce").ToString();
var tags = new List<string>();
tags.Add("doopy");
try
{
var svcs = new ServiceBusConnectionStringBuilder(AzureHub).ToString();
var hub = NotificationHubClient.CreateClientFromConnectionString(svcs, AzureName);
// what is this?
// var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var installation = new Installation(); // control tag registration
// FCM - works
installation.Platform = NotificationPlatform.Fcm;
installation.PushChannel = "put my fcm token here";
installation.InstallationId = "see comment..."; // from the device via this call: myNotificationHub.Register(FCMToken, new List<string>().ToArray()).RegistrationId;
if (ios)
{ // silently fails
installation.Platform = NotificationPlatform.Apns;
installation.InstallationId = "some guid I made up";
installation.PushChannel = "see comment"; // device token with <> and spaces removed from call mySBNotificationHub.RegisterNativeAsync(deviceToken...
}
installation.Tags = tags;
hub.CreateOrUpdateInstallationAsync(installation).Wait();
JObject data = MakeNotification("notificationId", "I got your tags doopy!");
var payload = PlatformPayload(ios, data);
Console.WriteLine("Send...");
if (ios)
hub.SendAppleNativeNotificationAsync(payload, tags).Wait();
else
hub.SendFcmNativeNotificationAsync(payload, tags).Wait();
Console.WriteLine("Message SENT!");
}
catch (Exception ex)
{
Console.WriteLine("rats! " + ex.Message);
}
}
I don't even use the mystery PushNotificationChannelManager from the docs and FCM works. That class seems to only exist in UWP or something.
It seems that APNS requires both an installation ID and a channel, but all I have is a device Id. Anyone know where to get these values for iOS?
So I have found a solution.
Take the iOS device token, remove spaces and angle brackets and use that for PushChannel. Create your own InstallationId (Guid.NewGuid().ToString(); and save it somewhere) or just use the device token for both fields.
I am developing web application on ASP.NET. In application users can purchase article for money.
For work with PayPal I using PayPal Merchant SDK for .NET package. Application work good with sandbox but with live display error: "This transaction is invalid". Please return to the recipient's website to complete your transaction using their regular checkout flow."
When user click on purchase button I execute code:
// only for live
var paypalConfig = new Dictionary<string, string> {
{"account1.applicationId", "<APP-LIVEID>"},
{"account1.apiUsername", "<username>"},
{"account1.apiPassword", "<pass>"},
{"account1.apiSignature", "<signature>"},
{"mode", "live"}};
try
{
var currency = CurrencyCodeType.USD;
var paymentItem = new PaymentDetailsItemType
{
Name = "item",
Amount = new BasicAmountType(currency, amount.ToString()),
ItemCategory = ItemCategoryType.DIGITAL,
};
var paymentItems = new List<PaymentDetailsItemType>();
paymentItems.Add(paymentItem);
var paymentDetail = new PaymentDetailsType();
paymentDetail.PaymentDetailsItem = paymentItems;
paymentDetail.PaymentAction = PaymentActionCodeType.SALE;
paymentDetail.OrderTotal = new BasicAmountType(currency, amount.ToString());
paymentDetail.SellerDetails = new SellerDetailsType {
PayPalAccountID= sellerEmail
};
var paymentDetails = new List<PaymentDetailsType>();
paymentDetails.Add(paymentDetail);
var ecDetails = new SetExpressCheckoutRequestDetailsType {
ReturnURL = returnUrl,
CancelURL = cancelUrl,
PaymentDetails = paymentDetails,
};
var request = new SetExpressCheckoutRequestType
{
Version = "104.0",
SetExpressCheckoutRequestDetails = ecDetails,
};
var wrapper = new SetExpressCheckoutReq
{
SetExpressCheckoutRequest = request
};
var service = new PayPalAPIInterfaceServiceService(paypalConfig);
var setECResponse = service.SetExpressCheckout(wrapper);
if (sandbox)
return "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={0}".FormatWith(setECResponse.Token);
return "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&TOKEN={0}".FormatWith(setECResponse.Token);
}
// # Exception log
catch (System.Exception ex)
{
// Log the exception message
Console.WriteLine("Error Message : " + ex.Message);
}
After all I redirect user to url with received TOKEN.
For my application, registered on PayPal, I set in options only "Adaptive Payments > Basic Payments > Checkout, Send Money or Parallel Payments"
Why live paypal payments can not work? What is the reason?
Removed
ItemCategory = ItemCategoryType.DIGITAL,
and all work
From previous experiences this problem usually comes from having a "null" token because of some mistake in the "setExpressCheckout" request (where, in the express checkout flow, you ask paypal for a transaction token).
Basically, you ask paypal for a token so you can build the redirect URL, but you make some mistake and paypal gives you an error but no token, so you build the URL with no token (or a wrong one).
If you try to redirect the user to the checkout URL ( https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={...}&useraction={...}) with an empty token you will get this error.
Actually I'm trying to know of there can be other causes...
http://www.asp.net/mvc/tutorials/mvc-4/using-oauth-providers-with-mvc
I'm using code from this tutorial (of course, not all). Everything works perfectly, but when I tried to pass email, I have System.Collections.Generic.KeyNotFoundException. Why? How can I pass e-mail value from Facebook?
return View("ExternalLoginConfirmation", new RegisterExternalLoginModel {
UserName = result.UserName,
ExternalLoginData = loginData,
FullName = result.ExtraData["name"],
Email = result.ExtraData["email"],
ProfileLink = result.ExtraData["link"],
});
This works:
return View("ExternalLoginConfirmation", new RegisterExternalLoginModel {
UserName = result.UserName,
ExternalLoginData = loginData,
FullName = result.ExtraData["name"],
//Email = result.ExtraData["email"],
ProfileLink = result.ExtraData["link"],
});
Regards
Facebook doesn't share Email addresses by default. See this post for more information, but you can change your registration model to require email when making a user registration for your site. Also, you can check that the collection has the key first, before trying to access it
AuthenticationResult result =
OAuthWebSecurity
.VerifyAuthentication(
Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
// Log in code
if (result.ExtraData.ContainsKey("email"))
// Use email
From my WSDL I have the following service part:
<service name="BAPI_CUSTOMER_DISPLAYService">
<documentation>SAP Service BAPI_CUSTOMER_DISPLAY via SOAP</documentation>
<port name="BAPI_CUSTOMER_DISPLAYPortType" binding="s0:BAPI_CUSTOMER_DISPLAYBinding">
<soap:address location="http://2.3.4.100:8000/sap/bc/soap/rfc"/>
</port>
</service>
then what will be endpoint reference for this?
I am giving it as "http://2.3.4.100:8000/sap/bc/soap/rfc" in my salesforce client and it gives the following error.
"This service requires client certificate for authentication procedure."
I am sure that i need to give user name and password not knowing how i can set them in my client which is a Apex code.
Help is appreciated.
I imported the Enterprise WSDL and used the uri from the loginResult. Here's some code from my project:
LoginResult loginResult = null; // Login Result (save and make static)
SessionHeader sessionHeader = null; // Session Header (save and make static)
SoapClient soapClient = null; // This is the Enterprise WSDL
SecureStatusClient SecureStatusClient = null; // This is my custom #WebService
// Create Login Request
LoginScopeHeader loginScopeHeader = new LoginScopeHeader
{
organizationId = configuration["OrganizationId"],
portalId = configuration["PortalId"]
};
// Call Login Service
string userName = configuration["UserName"];
string password = configuration["Password"];
string securityToken = configuration["SecurityToken"];
using (SoapClient loginClient = new SoapClient())
{
loginResult = loginClient.login(loginScopeHeader, userName, password + securityToken);
if (result.passwordExpired)
{
string message = string.Format("Salesforce.com password expired for user {0}", userName);
throw new Exception(message);
}
}
// Create the SessionHeader
sessionHeader = new SessionHeader { sessionId = loginResult.sessionId };
// Create the SoapClient to use for queries/updates
soapClient = new SoapClient();
soapClient.Endpoint.Address = new EndpointAddress(loginResult.serverUrl);
// Create the SecureStatusServiceClient
secureStatusClient = new SecureStatusServiceClient();
Uri apexUri = new Uri(SoapClient.Endpoint.Address.Uri, "/services/Soap/class/SecureStatusService");
secureStatusClient.Endpoint.Address = new EndpointAddress(apexUri);