I am utilizing an answer involving related code to that which is defined right here: How do I set return_uri for GoogleWebAuthorizationBroker.AuthorizeAsync?
What I’ve found after getting the code to work is that from the .NET Core Internet API; the authenticate technique opens a browser reasonably than sending the google authentication show to the iOS system. Clearly, this poses a little bit of a difficulty :).
I am positive it’s the newness I’ve to creating with this in a pseudo-middleware state of affairs however I am hoping another person has run into this case and can assist me perceive what I am doing incorrectly.
Visible Studio Undertaking contains the next:
— Observe: There is no such thing as a challenge reference between the 2 by design.
.NET 9 Maui Utility Undertaking – “MAUIAPP” —
.NET 9 Core Internet API Undertaking – “LogonAPI” — Runs on a port on “http:LocalHost”
Utilizing ngrok.exe to tunnel from https url supplied by them which factors to the event machine’s native http port — that is all working efficiently.
I’m deploying to a related iOS(Iphone) related to my growth machine to which the MAUIAPP is being deployed efficiently. I’ve a button on the principle web page which calls a service within the MAUIAPP “LogonService.cs” and a perform “LogonGoogle”.
The button factors to the url on my localhost port operating the .web core net api in debug mode and onclick efficiently instantiates and calls the remainder api within the controller:
[HttpGet("/GoogleAuth/Authenticate")]
public async Activity Authenticate()
{
strive
{
string[] Scopes = { "https://www.googleapis.com/auth/userinfo.profile" };
//requires full scope to get ACL listing..
UserCredential credential;
string ApplicationName = "HairTriggerProd3";
//simply reference the namespaces in your utilizing block
utilizing (var stream = new FileStream
(
"googleSecrets.json",
FileMode.Open,
FileAccess.Learn
)
)
{
// The file token.json shops the consumer's entry and refresh tokens, and is
// created
// routinely when the authorization move completes for the primary time.
string credPath = "googleSecretsRefresh";
credential = dsAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.FromStream(stream).Secrets and techniques,
Scopes,
"consumer",
CancellationToken.None,
new FileDataStore(credPath, true)).Consequence;
}
return Okay(credential);
}
catch (Exception x)
{
return BadRequest(x);
}
}
public class dsAuthorizationBroker : GoogleWebAuthorizationBroker
{
public static string RedirectUri = "https:[provided ngrok tunnel]/ReturnFromGoogle";
public new static async Activity AuthorizeAsync(
ClientSecrets clientSecrets,
IEnumerable scopes,
string consumer,
CancellationToken taskCancellationToken,
IDataStore dataStore = null)
{
var initializer = new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = clientSecrets,
};
return await AuthorizeAsyncCore(initializer, scopes, consumer,
taskCancellationToken, dataStore).ConfigureAwait(false);
}
non-public static async Activity AuthorizeAsyncCore(
GoogleAuthorizationCodeFlow.Initializer initializer,
IEnumerable scopes,
string consumer,
CancellationToken taskCancellationToken,
IDataStore dataStore)
{
initializer.Scopes = scopes;
initializer.DataStore = dataStore ?? new FileDataStore(Folder);
var move = new dsAuthorizationCodeFlow(initializer);
return await new AuthorizationCodeInstalledApp(move,
new LocalServerCodeReceiver())
.AuthorizeAsync(consumer, taskCancellationToken).ConfigureAwait(false);
}
}
public class dsAuthorizationCodeFlow : GoogleAuthorizationCodeFlow
{
public dsAuthorizationCodeFlow(Initializer initializer)
: base(initializer) { }
public override AuthorizationCodeRequestUrl
CreateAuthorizationCodeRequest(string redirectUri)
{
return base.CreateAuthorizationCodeRequest(dsAuthorizationBroker.RedirectUri);
}
}
When the invocation of the GoogleWebAuthorizationBroker’s AuthorizeAsync(… is named the net api opens the google problem in a browser window on my growth machine reasonably than on the system and as such the consumer won’t see the problem to pick out or enter credentials.
Can anybody assist a beginner right here with this situation and inform me how I ensure that the system is what receives the problem?