Skip to content

Added customUrlValidation #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 52 commits into from
Jul 17, 2019

Conversation

vytautas-pranskunas-
Copy link

Added custom url validation because we have an issue where we are calling optile requests for payment providers and there were only allowedUrls which we also have different like on local we have full url and on other environemtns calls are local and starts from 'api'. So with current allowedUrls there were not possibility to put allowed urls because it looks for startsWith. So i thought it is better to introduce custom url validation rather then add notAllowedUrls.

@vytautas-pranskunas-
Copy link
Author

I have also changed access level of storeAccessTokenResponse to public because there are situations where you have to do silent login that means that you receiving tokens from other sources and it would be really not good to add it manually to session storage because it should use same storage.

@vytautas-pranskunas-
Copy link
Author

I have synced masters so it is good to merge now. Is there a chance to get it merged sometime soon?

Copy link

@poke poke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rebase your changes against the current master instead of merging it? That will make the history cleaner and will likely make this PR easier to accept.

const found = !this.moduleConfig.resourceServer.customUrlValidation
? this.moduleConfig.resourceServer.allowedUrls.find(u => url.startsWith(u))
: this.moduleConfig.resourceServer.customUrlValidation(url);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could simplify this a bit to avoid having to check the customUrlValidation multiple times:

if (this.moduleConfig.resourceServer.customUrlValidation) {
    return this.moduleConfig.resourceServer.customUrlValidation(url);
}

if (this.moduleConfig.resourceServer.allowedUrls) {
    return !!this.moduleConfig.resourceServer.allowedUrls.find(u => url.startsWith(u));
}

return true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

@@ -39,7 +47,7 @@ export class DefaultOAuthInterceptor implements HttpInterceptor {
if (!this.moduleConfig.resourceServer) {
return next.handle(req);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move the moduleConfig.resourceServer check into the checkUrl function as well then?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not think this is good idea because there can be other configuration in resourceServer that are used not only for checking urls in the future. Dont you think so/ So i propose to leave it where it is

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you’re right. I missed that there were some other things used from resourceServer right after that line.

@@ -1216,7 +1216,7 @@ export class OAuthService extends AuthConfig {
}
}

private storeAccessTokenResponse(
public storeAccessTokenResponse(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should be a separate PR

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ideal world it might be. But i have really lack of time in playing with git now tring to split it into 2 merge requests + it is not breaking change it is just open one essential method to public. Maybe we can merge it like it is this time? :)

@vytautas-pranskunas-
Copy link
Author

Fixed comments

@poke
Copy link

poke commented Jun 5, 2018

I’m not in any way affiliated with this project, but the amount of commits in this pull request is really intimidating, especially considering the few actual changes this is introducing.

To clean that up, you could do git reset --soft origin/master and then make a new fresh commit (which will then include all the changes here), and finally push that using git push --force to update this pull request with that squashed commit.

And before you actually commit that, you might want to remove the changes to the package.json since that only includes whitespace changes.

@vytautas-pranskunas-
Copy link
Author

I have tried soft reset but there is nothing happening. Maybe t his is because i have rebased it i am not sure (not big git guru). Anyway - ammount of commits is big but changes are obivous. Decission is yours but i think functionality that is added is more important than commits history :)

@poke
Copy link

poke commented Jun 6, 2018

Oh, my bad, origin/master is your own master. Try git reset --soft b4c87312f5 instead.

And sure, the changes are obvious but if I was a maintainer of this (again: I am not involved with this project, I am just trying to contribute just like you), I would reject this because it is quite a mess. So I just want to give you the chance and offer help to fix it first before that happens :)

…r authentication flows like Silent Login within same software
@vytautas-pranskunas-
Copy link
Author

@poke thanks. Thats ofcourse is better. I did it.

@poke
Copy link

poke commented Jun 6, 2018

Cool, that looks much better, good job! 👍

@vytautas-pranskunas-
Copy link
Author

Any chance to merge it? :)

@jeroenheijmans
Copy link
Collaborator

Disclaimer: I'm no maintainer or expert, but followed this PR with interest.

Some additional feedback I found while looking through the code.

  1. I suggest changing the name for the custom validator property to allowedUrlValidator because then it shows up right next to allowedUrls in intellisense, making it easier for users to spot that they should use one or the other. Essentially, these settings are mutually exclusive. (In addition, this name conveys the typing a bit better IMHO)
  2. It might be good to update docs along this change as well?

@vytautas-pranskunas-
Copy link
Author

That makes sense and I will do it when maintainer will tell that he is going to merge it.

Fabian Wiles and others added 11 commits June 16, 2018 11:53
- Fixed some spelling errors
- Fixed some newlines (add/remove) based on other code around it
- Made capitalization and interpunction usage more consistent
- Fixed some jsdoc comment alignment issues
- Made small textual clarifications in some places
After further discussion and research in manfredsteyer#368 I noticed that even
though RFC 7617 seems to state that:

> Note that both scheme and parameter names are matched
> case-insensitively.

All the examples use "Basic" instead of "BASIC". There is one very
notable framework that checks case *sensitively* for "Basic". Given
that the header was incorrect anyways, we can be sure that changing
this casing won't further break anything, and work around issues for
server side frameworks like Spring.

See: https://tools.ietf.org/html/rfc7617
See: https://github.com/spring-projects/spring-security/blob/5.0.6.RELEASE/web/src/main/java/org/springframework/security/web/authentication/www/BasicAuthenticationFilter.java#L157

Fixes manfredsteyer#368
@manfredsteyer manfredsteyer added the investigation-needed Indication that the maintainer or involved community members may need to investigate more. label Sep 19, 2018
manfredsteyer and others added 17 commits September 19, 2018 19:58
Make all of the login functions return Promise<boolean>
WIP: feat: remove jsrsasign dependancy
Session check changed to run outside of Angular zone
Set accessibility for properties and methods to protected
In manfredsteyer#30 the maintainer @manfredsteyer mentions adding an MIT license, but
in 5b8cbbe it was accidentally removed. In manfredsteyer#385 it was mentioned that
the license should be added back. So that's what we do here!

Fixes manfredsteyer#370
See also manfredsteyer#385
See also manfredsteyer#30
Added option to set up silent refresh only for certain type of token.
@react-state
Copy link

Is there a chance to merge this someday because because of this we need to keep fix in our local npm and cannot migrate to version 5 :(

@vytautas-pranskunas-
Copy link
Author

Hello again. I made this pull requests without conflicts again. Maybe you can accept it?
I will explain problem again:
I added customUrlValidation function that validates url in addition to allowedUrls. Because when you have 20 countries with 4 environments each where api urls can be changed by devops without from time to time allowedUrls is not enough and can be painful.

p.s.
We are waiting for this for half a year now. ;)

@manfredsteyer manfredsteyer merged commit d66c82a into manfredsteyer:master Jul 17, 2019
@@ -39,7 +47,7 @@ export class DefaultOAuthInterceptor implements HttpInterceptor {
if (!this.moduleConfig.resourceServer) {
return next.handle(req);
}
if (this.moduleConfig.resourceServer.allowedUrls && !this.checkUrl(url)) {
if (!this.checkUrl(url)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this change after the merge of the PR, the final code still has
if (this.moduleConfig.resourceServer.allowedUrls && !this.checkUrl(url)) {
I need to set both allowedUrls and customUrlValidation to make it work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR created #584

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigation-needed Indication that the maintainer or involved community members may need to investigate more.
Projects
None yet
Development

Successfully merging this pull request may close these issues.