Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

Get base url in angular outside of component

We're using the Msal library to handle authentication and it takes a redirect URL, which has to be the same one the user is accessing to work properly.

The config for that is in the app.module.ts, before defining the NgModules, so I can't get the router in a constructor. Is there a way there to get the base domain the user is accessing ?

I have been using an environment variable to store this for now but it's very limiting, I'd like it to work for multiple domains transparently. Since the redirect url are stored and verified by microsoft anyway during authentication, passing whatever the user is accessing from the frontend should be fine.

Thank you

question from:https://stackoverflow.com/questions/65883537/get-base-url-in-angular-outside-of-component

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Hadn't realized this was an optional config :

redirectUrl: Location to redirect, can be a relative of absolute url. (optional, default: window.location.href);

The default is actually what I'm looking for, so nevermind ! Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...