Launching a Universal Windows App using Angular by extracting URI data from the browser for seamless automatic login

Can you provide guidance on launching a UWP app from Angular code using a URI from the browser and passing user information such as userid, password, and other details? We need to encrypt the credentials in the Angular app and decrypt them in the UWP app.

Answer №1

How can we initiate the launch of a UWP app using angular code and a URI from a browser, while passing user information to it?

In order to achieve this scenario, you can follow the guidance provided in Handle URI activation. Register your app with a URI scheme and when you launch the specific URL, you can retrieve the path and parameters from the app's OnActivated method.

For example:

<a href="testapp:login?userid=1234&password=7894">Launch</a>

App OnActivated:

public static Dictionary<string, string> ParseQueryString(Uri url)
 {    
     if (string.IsNullOrWhiteSpace(url.Query))
     {
         return new Dictionary<string, string>();
     }
    
     var dic = url.Query.Substring(1)
         
             .Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries)
           
             .Select(param => param.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries))
         
             .GroupBy(part => part[0], part => part.Length > 1 ? part[1] : string.Empty)
       
             .ToDictionary(group => group.Key, group => string.Join(",", group));

     return dic;
 }
 protected override void OnActivated(IActivatedEventArgs e)
 {
     // set up frame
     Frame rootFrame = Window.Current.Content as Frame;

     if (rootFrame == null)
     {
         // Create a Frame to act as the navigation context and navigate to the first page
         rootFrame = new Frame();
         rootFrame.NavigationFailed += OnNavigationFailed;

         Window.Current.Content = rootFrame;
     }

     Type deepLinkPageType = typeof(MainPage);
     if (e.Kind == ActivationKind.Protocol)
     {
         var protocolArgs = (ProtocolActivatedEventArgs)e;
         var dict = ParseQueryString(protocolArgs.Uri);
         switch (protocolArgs.Uri.AbsolutePath)
         {
             case "":
                 break;
             case "login":
                 //navigate to login page with above dict parameter
                 break;
          
         }
     }

     if (rootFrame.Content == null)
     {
         // Default navigation
         rootFrame.Navigate(deepLinkPageType, e);
     }
     // Ensure the current window is active
     Window.Current.Activate();
 }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

import component dynamically from object in Next.js

Currently, I have a collection of components that I am aiming to dynamically import using next/dynamic. I'm curious if this is achievable. Here's the object in interest: // IconComponents.tsx import { Tick, Star } from 'components ...

Issues with unit tests arising from property bindings in a reusable Angular modal component are causing failures

I have successfully developed a reusable Modal component that works perfectly fine when running ng serve without any errors in the console. However, I encountered an issue when running ng test where I received the error message "Template parse errors: Can& ...

Implement the properties encapsulation design pattern

In need of a method to control document activation logic, where activating a document involves adding it to a list of activeDocuments and setting a flag to true. Direct access to the isActive property should be prohibited. class DocumentService { pr ...

Challenge with sharing an array from a different component in Angular using @Input()

Recently, I started learning Angular and decided to create a basic blog application. While trying to retrieve a property from another component using the @Input() decorator, I encountered an issue specifically related to arrays. In a post-list-item compone ...

Error: Unable to retrieve URL from environment variable UPSTASH_REDIS_REST_URL in the parsing process

Encountering an issue with TypeScript while attempting to create a new Redis instance. I've set up an .env.local file with matching names for the redis URL and token. import { Redis } from '@upstash/redis' export const db: Redis = new Redis ...

Exploring the process for transitioning between pages within Angular

I am working on an Angular project and I am looking to navigate to the registration page when the registration button is clicked. As a beginner, I attempted to link the registration page but encountered some issues. My goal is for the main page to disappea ...

Creating a String-only pattern Validator: A step-by-step guide

Below is the code I've written: ***<input type="text" placeholder="First Name" name="firstName1" [(ngModel)]="firstName" #firstName1="ngModel" required pattern="^[a-z0-9_-]{8,15}$" >*** ...

Stop any modifications to the input data

We are currently in the process of building an angular application with Angular 5. Typically, our components have input and output parameters defined as shown below: export class MultipleItemPickerComponent implements OnInit { @Input() itemPickerHeader ...

Eliminating the "as" keywords from the TypeScript code

I'm looking to optimize this TypeScript code by removing the unnecessary as keywords. The code includes a method called update where I'm attempting to improve the organization of sanitizing, validating, and attributing data. However, it seems tha ...

Exploring the <> syntax in Angular2 with Typescript

I am brand new to Angular2 and struggling to grasp the < > syntax : For instance, in example 1 (found at https://angular.io/docs/ts/latest/guide/dependency-injection.html): let mockService = <HeroService> {getHeroes: () => expectedHeroes } ...

Angular 2's ng-bootstrap datepicker popup feature allows users to easily select

Greetings! I have been exploring the ng-bootstrap datepicker and managed to implement it successfully in my application after studying the demo code. However, when attempting to add more than one datepicker input tags, only one seems to be functioning pro ...

Tips for transferring information from a Sidemenu to a different page during navigation

Essentially, I have two types of users: Teachers and Students. How can I display different profile screens depending on the user type? The Sidemenu is located in app.components.ts file. ...

Enhancing the appearance of TypeScript and React with custom styling using the NPM package

I'm currently working on a TypeScript (TS), React project where I have organized all my React components. To make things easier, I decided to create an NPM package out of this project and use it in various separate React projects. However, I've e ...

The function has exceeded the time limit of 60000 milliseconds. Please make sure that the callback is completed

Exploring the capabilities of Cucumber with Protractor has been an intriguing journey for me. As I delved into creating a feature in Gherkin language, outlining the steps and scenarios necessary for my end-to-end tests, a new world of possibilities opened ...

Whenever I attempt to reload a page on my Angular http-server, I receive a "Page Not Found" error

Whenever I try to refresh a page on my Angular application running on an http-server, the browser displays a "Page Not Found" error. Can anyone provide assistance with resolving this issue? ...

Troubleshooting Routing Issues in Deployed Angular Application on GitPages

Disclaimer: Although I am not a frontend developer by profession, I have been tasked with deploying an Angular application that was created by other engineers. I have attempted to deploy the Angular application on GitPages and also experimented with the c ...

Null value returned by getDOM() function during transition from Angular 2 to Angular 4

I've encountered a unique challenge that has me stumped. Despite finding similar issues, the proposed solutions don't seem to work for my case. My issue arose when I decided to migrate a project from Angular 2 to Angular 4. I began by creating a ...

What is the best way to retrieve an array stored within a key of a JSON object within an Angular service?

I have been learning about Angular heroes through a tutorial and decided to apply my knowledge in a small test project. While it worked fine with mock items using the built-in http server, I am facing difficulties retrieving items from a Django REST API. ...

The attempt to connect Apache NiFi on a Windows machine to a MySQL database on the same host was unsuccessful

I am currently facing an issue with connecting my Apache NiFi running on a Windows machine to a MySQL database hosted on localhost. Despite ensuring that the database is accessible from any host, I have been unsuccessful in establishing the connection. At ...

Checking the functionality of a feature with Jasmine framework in an Angular application

I am working on writing unit test cases and achieving code coverage for the code snippet below. Any advice on how to proceed? itemClick($event: any) { for (let obj of this.tocFiles) { let results = this.getchildren(obj, label); if (results) { conso ...