Retrieving ACCESS_TOKEN from Instagram redirect using Angular 5 (Implicit Authentication)

Building a frontend app without a backend, I have decided to use Instagram implicit authentication. However, once the user authorizes the app, Instagram redirects to my redirect_uri with the access token in this format:

http://your-redirect-uri#access_token=ACCESS-TOKEN
. How can I properly extract the access token from this? I attempted to use the router but encountered difficulties due to the '#' character.

Answer №1

To access all parameters starting from #, you can utilize window.location.hash. Alternatively, you can use window.location.href to access the full URL. If you want to retrieve the token, you can employ

window.location.hash.match(/#access_token=([^&]+)/)[1]
.

Please note: If you are working with TypeScript, remember to import window in your component.

declare let window;

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

"Exploring the New Feature of Angular 17: Named Router Outlets Implemented

One issue I am facing with my application is the rendering of different pages based on whether a user is logged in or not. The generic pages like the landing or logout page should be displayed within the primary router-outlet when the user is not logged in ...

Specializing in narrowing types with two generic parameters

In my current project, I am working on a function that takes two generic parameters: "index" which is a string and "language" which can also be any string. The goal of the function is to validate if the given language is supported and then return a formatt ...

Utilizing an image as a background using [ngStyle] in Angular 5

I attempted to set the background of a Div element with an image saved in the database using [ngStyle] in Angular, but unfortunately it did not work as expected. <div class="image" [ngStyle]="{'background': ' url(' + imageUrl + &ap ...

Tips on avoiding tab selection in ngx-bootstrap

My current setup includes two tabs using ngx-bootstrap as shown below. I am looking to disable the tab functionality programmatically: <tabset> <tab heading="First">Tab 1 content</tab> <tab heading="Second">Tab 2 content< ...

Guide to developing a personalized useReducer with integrated decision-making and event activation

I am interested in creating a custom hook called useTextProcessor(initialText, props). This hook is designed for managing and manipulating text (string) within a React state. It utilizes useReducer to maintain a cumulative state. Here is the implementation ...

Bootstrapping Angular2 asynchronously using an external JSON configuration file

After upgrading to angular2 RC6, I am facing a challenge in loading an external JSON config file before bootstrapping my AppModule. It was working fine with RC5 but now I am struggling to find the equivalent way of injecting this data. /** Create dummy XS ...

Retrieve a collection of Firestore documents based on an array of unique identifiers

I have a Firestore collection where one of the values is an array of document IDs. My goal is to retrieve all items in the collection as well as all documents stored within the array of IDs. Here is the structure of my collection: https://i.sstatic.net/rA8 ...

Is it possible that overwriting my observable variable will terminate existing subscribers?

I am looking for a way to cache an http call and also trigger the cache refresh. My UserService is structured like this: @Injectable() export class UserService { private currentUser$: Observable<User>; constructor(private http: HttpClient) { } ...

Determining if a number exceeds 3 decimal points using AngularJS

I have encountered a problem where I need to determine if a value has more than three decimal places in AngularJS. Although I am familiar with checking if a value is a whole number or greater than zero, I am unsure how to perform this specific task. Below ...

Unable to assign user roles in next-auth due to the absence of matching modifiers for user

I am currently working on implementing user roles in next-auth. Within my database, I have defined a prisma enum UserRole with the values 'ADMIN' and 'USER'. In my auth.ts file, I included the role property in the session object and enc ...

Angular UI and Node backend causing CORS issues

Just diving into the world of node and could use a little assistance. Encountering this error message: Access to XMLHttpRequest at 'http://localhost:3000/api/auth/signin' from origin 'http://localhost:4200' has been blocked by CORS pol ...

There are no call signatures available for the unspecified type when attempting to extract callable keys from a union

When attempting to write a legacy function within our codebase that invokes methods on certain objects while also handling errors, I encountered difficulty involving the accuracy of the return type. The existing solution outlined below is effective at cons ...

There was a Runtime Error that occurred, stating a TypeError: It is not possible to access properties of an undefined value (specifically

I've encountered an issue with a donut chart implemented from react-apex charts. Every time I try to render the page containing the chart, an error occurs. However, if I make changes to a property of the chart, it renders without any errors on the fro ...

As I iterated over the Vehicles API data, I encountered an issue while trying to access specific Vehicle information. I received an error message stating "Cannot read property 'id' of undefined

Exploring the realms of Angular, with some experience in older versions, I find myself faced with a challenge involving two APIs - "/vehicles" and "/vehicle/{id}". The process involves fetching data from "/vehicles", iterating through it to match IDs, the ...

What is the method for identifying the corresponding value that should be linked to the remaining select based on the selected option?

Is it possible for the first select to dynamically affect the value of another select? <form [formGroup]="myForm"> <div class="modal-body"> <p><strong>Rate:</strong></p> {{ApplesPerCash}} <p><st ...

Refresh Angular component upon navigation

I have set up routes for my module: const routes: Routes = [ { path: ":level1/:level2/:level3", component: CategoriesComponent }, { path: ":level1/:level2", component: CategoriesComponent}, { path: ":level1", component: ...

Utilizing the power of HTML5 drag and drop functionality in conjunction with Angular Material 2's md

When working with Angular Material 2 and attempting to enable reordering of list elements, I encountered an issue where the functionality works perfectly for li-tag but fails with md-list-item. Why is that? Here is a snippet of my template: <md-nav-li ...

The declaration file for the datepicker module could not be located, even though the necessary types have been installed

I'm encountering an issue during production build on my Next.js project. The error message reads: Could not find a declaration file for module 'react-datepicker'. '../node_modules/react-datepicker/dist/index.js' implicitly has an ...

Tips for sending information to an ng-bootstrap tooltip

Currently, I am in the process of developing an Angular application with Bootstrap and utilizing ng-bootstrap. One specific component that I have created is a popover which contains the following HTML structure: HTML (popover component) <div> < ...

Images in Angular 2 not appearing until system reboot

When working with angular2 and nodejs to upload an image, I encounter an issue where after node uploads the file to the assets folder, an error occurs when attempting to display it in angular: GET http://localhost:4200/assets/img/3.jpg 404 (Not Found) In ...