This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future main() async { | |
... | |
String? token; | |
if (kIsWeb) { | |
token = Uri.base.queryParameters['token']; | |
} | |
runApp(MyApp(token: token)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future main() async { | |
... | |
String? token; | |
if (kIsWeb) { | |
token = Uri.base.queryParameters['token']; | |
} | |
runApp(MyApp(token: token)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<ActionResult> IndexAsync(string id_token, string state) | |
{ | |
if (string.IsNullOrEmpty(id_token) || string.IsNullOrEmpty(state) || !state.Contains(';')) | |
return this.BadRequest(); | |
string platform = state.Split(';')[0]; | |
if (!Guid.TryParse(state.Split(';')[1], out Guid emailValidationTokenId)) | |
return this.BadRequest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HomeController : Controller | |
{ | |
[HttpGet] | |
public ActionResult Index(string platform, string provider, string token) | |
{ | |
string url; | |
if (provider == "apple") | |
url = "https://appleid.apple.com/auth/authorize" + | |
"?client_id=com.your.app" + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future validateEmailWithOAuth2AndLogin(LoginMethod loginMethod) async { | |
// Creates an empty email validation token on server-side so we have its ID | |
EmailValidationToken emailValidationToken = await beginOAuth2EmailValidation(loginMethod); | |
String url = 'https://auth.youapp.com/?${kIsWeb ? 'platform=web&' : ''}provider=${loginMethod.name}&token=${emailValidationToken.id}'; | |
if (await canLaunchUrlString(url)) { | |
// Open the URL in a new browser window on all the platforms except web | |
await launchUrlString( | |
url, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task<string> GetEmailFromGoogleCode(string googleCode) | |
{ | |
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow( | |
new GoogleAuthorizationCodeFlow.Initializer | |
{ | |
ClientSecrets = new ClientSecrets() | |
{ | |
ClientId = "XXXXXXXXXX.apps.googleusercontent.com", | |
ClientSecret = "XXXXXXXXXX" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task<string> GetEmailFromAppleCode(string appleCode) | |
{ | |
string privateKey = System.IO.File.ReadAllText(Path.Combine(this.environment.ContentRootPath, "AuthKey_XXXXXXXXXX.p8")); | |
AppleAuthProvider provider = new AppleAuthProvider( | |
"com.your.app", | |
"XXXXXXXXXX", | |
"XXXXXXXXXX", | |
"https://auth.yourapp.com/callback", // I don't know why it must be here but it is not used | |
string.Empty | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!kIsWeb && Platform.isAndroid) { | |
GoogleSignIn googleSignIn = GoogleSignIn( | |
scopes: <String>['email'], | |
); | |
try { | |
GoogleSignInAccount account = (await googleSignIn.signIn())!; | |
// Send the account.serverAuthCode to your server to exchange it for the token | |
await validateEmailWithGoogleAndLogin(account.serverAuthCode!); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!kIsWeb && (Platform.isIOS || Platform.isMacOS)) { | |
AuthorizationCredentialAppleID credential = await SignInWithApple.getAppleIDCredential( | |
scopes: [AppleIDAuthorizationScopes.email], | |
); | |
// Send the credential.authorizationCode to your server to exchange it for the token | |
await validateEmailWithAppleAndLogin(credential.authorizationCode); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override void OnActionExecuting(ActionExecutingContext actionExecutingContext) | |
{ | |
base.OnActionExecuting(actionExecutingContext); | |
this.HandleViewModelMultilingualProperties(actionExecutingContext); | |
} | |
private void HandleViewModelMultilingualProperties(ActionExecutingContext actionExecutingContext) | |
{ | |
ViewModelBase viewModel = this.GetViewModelFromActionExecutingContext(actionExecutingContext); |
NewerOlder