Skip to content
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

Add a login with Google Authorization Server Sample #106

Closed
asaikali opened this issue Sep 1, 2020 · 19 comments
Closed

Add a login with Google Authorization Server Sample #106

asaikali opened this issue Sep 1, 2020 · 19 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@asaikali
Copy link

asaikali commented Sep 1, 2020

The current sample authorization server uses spring security form login. A sample showing how to have the authorization server delegate to google or another social login provider is quite useful. For my use case I to be able to support from based login and social OIDC logins. Implementing this sample can help ensure that the configuration APIs are flexible enough to allow multiple authentication providers.

@asaikali asaikali added the type: enhancement A general enhancement label Sep 1, 2020
@jgrandja jgrandja added this to the 0.0.2 milestone Sep 2, 2020
@jgrandja jgrandja removed this from the 0.0.2 milestone Sep 30, 2020
@jgrandja jgrandja added the status: on-hold We can't start working on this issue yet label Oct 15, 2020
@erikmartino
Copy link

erikmartino commented Jan 12, 2021

There should probably be two different where the user can choose between them at login, for example Google and Github. If you host a SAAS solution, it is quite useful to delegate authentication to each customer organisations own OIDC provider.

@ojhughes
Copy link

ojhughes commented Feb 9, 2021

I was thinking about this, should the authorization server ever delegate authorization? I understand the authorization server would delegate the storage of users / credentials to LDAP or a DB but I thought that the process of authorizing a client should be performed by the authorization server. The existing Spring resource server already works with the various social logins.

@jgrandja
Copy link
Collaborator

@ojhughes

should the authorization server ever delegate authorization

There are a number of OAuth/OIDC providers that deliver this type of feature via Social login authorization delegation. This is typically delivered in a product, so it's not clear if we would deliver such support within the framework.

Either way, it will be a good exercise to deliver a sample that demonstrates this authorization delegation pattern.

@pangyiwei
Copy link

pangyiwei commented Mar 25, 2021

I tried something for this:

  1. Add spring-boot-starter-oauth2-client to the authorization project dependencies
  2. Configure the default security filter chain with the oauth2Login().
  3. Update application.yml with the oauth2 client registration config (With your Google OAuth2 Credentials)

Would this be right for the sample? Would be glad to submit a PR for this if necessary

@jgrandja
Copy link
Collaborator

@pangyiwei The sample you created does not integrate Authorization Server. It simply uses client features only. We would need the authorization related data to be stored via OAuth2AuthorizationService. The sample you have stores the data via OAuth2AuthorizedClientService.

@pangyiwei
Copy link

@jgrandja Ahh I see. I had the impression that this could be done similarly to how the sample was for the form login where the resource owner will have to be authenticated (by Google) first before the authorization is saved by OAuth2AuthorizationService. Noted that this was the flow done in processAuthorizationRequest() in the OAuth2AuthorizationEndpointFilter class. Hence, I thought that the sample would mainly involve configuration of Google as an OAuth2 client (for the authorization server).

Thank you for the clarification.

@natami
Copy link

natami commented Oct 1, 2021

Any progress/timeline on this issue?

@jgrandja jgrandja self-assigned this Oct 25, 2021
@jgrandja jgrandja removed the status: on-hold We can't start working on this issue yet label Oct 25, 2021
@jgrandja jgrandja added this to the 0.2.1 milestone Oct 25, 2021
@fwollsch
Copy link

@jgrandja it definitely works as of 0.2.0
Nothing special required to make it work either. The oauth2Login has to be configured on both HttpSecurity configurations (oauth2-server and globally) of course, but this is also the case for the formLogin.

https://github.com/gw2auth/oauth2-server/blob/main/src/main/java/com/gw2auth/oauth2/server/configuration/SecurityConfiguration.java
https://github.com/gw2auth/oauth2-server/blob/main/src/main/java/com/gw2auth/oauth2/server/configuration/OAuth2ServerConfiguration.java

@jgrandja
Copy link
Collaborator

jgrandja commented Oct 28, 2021

Thanks for looking into this @fwollsch. I suspected it would work, however, there is another implementation strategy that could provide tighter integration with SpringAS. I'll be looking into this soon.

@schepuri-bisc
Copy link

Hello @jgrandja, thanks for looking into this. I'm looking for a sample SpringAS project that does federated authentication using external identity providers. Could you please share any progress?

@jgrandja
Copy link
Collaborator

@schepuri-bisc I haven't started it yet but it's planned for the 0.2.3 release. Working on other higher priority tasks.

sjohnr added a commit to sjohnr/spring-authorization-server that referenced this issue Feb 4, 2022
sjohnr added a commit to sjohnr/spring-authorization-server that referenced this issue Feb 4, 2022
sjohnr added a commit to sjohnr/spring-authorization-server that referenced this issue Feb 8, 2022
sjohnr added a commit to sjohnr/spring-authorization-server that referenced this issue Feb 8, 2022
sjohnr added a commit to sjohnr/spring-authorization-server that referenced this issue Feb 25, 2022
sjohnr added a commit to sjohnr/spring-authorization-server that referenced this issue Feb 28, 2022
sjohnr added a commit to sjohnr/spring-authorization-server that referenced this issue Feb 28, 2022
sjohnr added a commit to sjohnr/spring-authorization-server that referenced this issue Feb 28, 2022
@sjohnr sjohnr linked a pull request Feb 28, 2022 that will close this issue
sjohnr added a commit to sjohnr/spring-authorization-server that referenced this issue Mar 3, 2022
sjohnr added a commit to sjohnr/spring-authorization-server that referenced this issue Mar 3, 2022
@jgrandja jgrandja assigned sjohnr and unassigned jgrandja Mar 11, 2022
sjohnr added a commit to sjohnr/spring-authorization-server that referenced this issue Mar 17, 2022
sjohnr added a commit to sjohnr/spring-authorization-server that referenced this issue Mar 17, 2022
sjohnr added a commit to sjohnr/spring-authorization-server that referenced this issue Mar 22, 2022
jgrandja pushed a commit that referenced this issue Mar 22, 2022
@jgrandja
Copy link
Collaborator

This sample is now in main via 3fe6f86

@imaxkhan
Copy link

hi
i checked the sample
can we use azure active directory b2c as identity provider for federating authentication? what would be application.yml properties for azure?

@sjohnr
Copy link
Member

sjohnr commented Jan 20, 2023

Sorry @imaxkhan, I'm sure you can use AD but I don't know that information off-hand. You will want to check the documentation for your provider. It should be fairly similar to the sample.

@imaxkhan
Copy link

hi in this example u are adding custom claims to ID_TOKEN
is there any way to add custom claims to ACCESS_TOKEN? because API calls are being done by ACCESS_TOKEN

@imaxkhan
Copy link

Sorry @imaxkhan, I'm sure you can use AD but I don't know that information off-hand. You will want to check the documentation for your provider. It should be fairly similar to the sample.

yes as u said its working now..tnx

@sjohnr
Copy link
Member

sjohnr commented Feb 17, 2023

@imaxkhan feel free to submit any questions you have to Stack Overflow and we can take a look. We prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it). Having said that,

hi in this example u are adding custom claims to ID_TOKEN is there any way to add custom claims to ACCESS_TOKEN? because API calls are being done by ACCESS_TOKEN

In FederatedIdentityIdTokenCustomizer, there is:

if (OidcParameterNames.ID_TOKEN.equals(context.getTokenType().getValue())) {
    // ...
}

You can simply do:

if (OAuth2ParameterNames.ACCESS_TOKEN.equals(context.getTokenType().getValue())) {
    // ...
}

@imaxkhan
Copy link

imaxkhan commented Feb 17, 2023

@imaxkhan feel free to submit any questions you have to Stack Overflow and we can take a look. We prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it). Having said that,

hi in this example u are adding custom claims to ID_TOKEN is there any way to add custom claims to ACCESS_TOKEN? because API calls are being done by ACCESS_TOKEN

In FederatedIdentityIdTokenCustomizer, there is:

if (OidcParameterNames.ID_TOKEN.equals(context.getTokenType().getValue())) {
    // ...
}

You can simply do:

if (OAuth2ParameterNames.ACCESS_TOKEN.equals(context.getTokenType().getValue())) {
    // ...
}

just add same thing before like this:
@OverRide
public void customize(JwtEncodingContext context) {
if (OAuth2ParameterNames.ACCESS_TOKEN.equals(context.getTokenType().getValue())) {
extractClaims(context.getPrincipal());
}
}

private Map<String, Object> extractClaims(Authentication principal) {
    OAuth2User oAuth2User = (OAuth2User) principal.getPrincipal();
    Map<String, Object> attributes = oAuth2User.getAttributes();
    attributes.put("sub","dsdsdds");
    return attributes;
}

but we can not change attributes in access token because it is unmodifiable
the error:
java.lang.UnsupportedOperationException: null
at java.base/java.util.Collections$UnmodifiableMap.put(Collections.java:1505) ~[na:na]

I just one to add some custom claims to access token and in resource sever with custom token convertor access to this claim..but ur example only deals with ID_TOKEN

now i change it like this:
private Map<String, Object> extractClaims(Authentication principal) {
OAuth2User principal1 = (OAuth2User) principal.getPrincipal();
Map<String, Object> claims = new HashMap<>(principal1.getAttributes());
claims.put("sub", "sa");
claims.put("xyz", "da");
return claims;

but in resource server again claims in access token not being changed..even my custom claims

@sjohnr
Copy link
Member

sjohnr commented Feb 24, 2023

@imaxkhan, this is covered in the How-to guides in the reference and in the Federated Identity Sample. If you have further questions, please use Stack Overflow.

doba16 pushed a commit to doba16/spring-authorization-server that referenced this issue Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants