public static async void LaunchGoogleAuthUri() { var state = UtilityService.GenerateRandomDataBase64Url(32); var codeVerifier = UtilityService.GenerateRandomDataBase64Url(32); var codeChallenge = UtilityService.EncodeBase64UrlNoPadding(UtilityService.ConvertToSha256(codeVerifier)); const string codeChallengeMethod = "S256"; var localSettings = ApplicationData.Current.LocalSettings; localSettings.Values["state"] = state; localSettings.Values["codeVerifier"] = codeVerifier; var authorizationRequest = $"{GoogleAuthorizationEndpoint}?response_type=code" + $"&scope=openid%20profile%20{YouTubeReadOnlyScope}%20{YouTubeUploadScope}" + $"&redirect_uri={Uri.EscapeDataString(AuthorizationRedirectUri)}" + $"&client_id={YouTubeApiClientId}" + $"&state={state}" + $"&code_challenge={codeChallenge}" + $"&code_challenge_method={codeChallengeMethod}"; await Launcher.LaunchUriAsync(new Uri(authorizationRequest)); }
/// <summary> /// Returns URI-safe data with a given input length. /// </summary> /// <param name="length">Input length (nb. output will be longer)</param> /// <returns></returns> public static string GenerateRandomDataBase64Url(uint length) { IBuffer buffer = CryptographicBuffer.GenerateRandom(length); return(UtilityService.EncodeBase64UrlNoPadding(buffer)); }