-
Notifications
You must be signed in to change notification settings - Fork 56
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
Added support for pushed authorization request #49
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
uber-core/src/main/java/com/uber/sdk/core/auth/internal/LoginPARResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.uber.sdk.core.auth.internal; | ||
|
||
import com.squareup.moshi.Json; | ||
|
||
public class LoginPARResponse { | ||
@Json(name = "request_uri") | ||
public String requestUri; | ||
@Json(name = "expires_in") | ||
public String expiresIn; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
uber-core/src/main/java/com/uber/sdk/core/auth/internal/ProfileHint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.uber.sdk.core.auth.internal; | ||
|
||
import com.squareup.moshi.Json; | ||
|
||
import java.io.Serializable; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public class ProfileHint implements Serializable { | ||
|
||
@Json(name = "first_name") | ||
private final String firstName; | ||
@Json(name = "last_name") | ||
private final String lastName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should explicitly set @JSON field name on all these. |
||
private final String email; | ||
private final String phone; | ||
|
||
private ProfileHint( | ||
String firstName, | ||
String lastName, | ||
String email, | ||
String phone) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
this.email = email; | ||
this.phone = phone; | ||
} | ||
|
||
public static class Builder { | ||
private String firstName; | ||
private String lastName; | ||
private String email; | ||
private String phone; | ||
public Builder firstName(@Nonnull String firstName) { | ||
this.firstName = firstName; | ||
return this; | ||
} | ||
|
||
public Builder lastName(@Nonnull String lastName) { | ||
this.lastName = lastName; | ||
return this; | ||
} | ||
|
||
public Builder email(@Nonnull String email) { | ||
this.email = email; | ||
return this; | ||
} | ||
|
||
public Builder phone(@Nonnull String phone) { | ||
this.phone = phone; | ||
return this; | ||
} | ||
|
||
public ProfileHint build() { | ||
return new ProfileHint( | ||
firstName, | ||
lastName, | ||
email, | ||
phone | ||
); | ||
} | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public String getPhone() { | ||
return phone; | ||
} | ||
|
||
public Builder newBuilder() { | ||
return new Builder() | ||
.firstName(firstName) | ||
.lastName(lastName) | ||
.email(email) | ||
.phone(phone); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
uber-core/src/main/java/com/uber/sdk/core/client/internal/LoginPARRequestException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.uber.sdk.core.client.internal; | ||
|
||
public class LoginPARRequestException extends RuntimeException { | ||
LoginPARRequestException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...core/src/main/java/com/uber/sdk/core/client/internal/LoginPushedAuthorizationRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.uber.sdk.core.client.internal; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
import com.squareup.moshi.JsonAdapter; | ||
import com.squareup.moshi.Moshi; | ||
import com.uber.sdk.core.auth.internal.LoginPARResponse; | ||
import com.uber.sdk.core.auth.internal.OAuth2Service; | ||
import com.uber.sdk.core.auth.internal.ProfileHint; | ||
import com.uber.sdk.core.client.SessionConfiguration; | ||
|
||
import java.util.Base64; | ||
import java.util.Locale; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.Response; | ||
import retrofit2.Retrofit; | ||
import retrofit2.converter.moshi.MoshiConverterFactory; | ||
|
||
public class LoginPushedAuthorizationRequest { | ||
|
||
private final OAuth2Service oAuth2Service; | ||
|
||
private final Callback callback; | ||
private final ProfileHint profileHint; | ||
private final String clientId; | ||
private final String responseType; | ||
private final Moshi moshi; | ||
|
||
public LoginPushedAuthorizationRequest( | ||
SessionConfiguration sessionConfiguration, | ||
String responseType, | ||
Callback callback | ||
) { | ||
this( | ||
createOAuthService(sessionConfiguration.getLoginHost()), | ||
sessionConfiguration.getProfileHint(), | ||
sessionConfiguration.getClientId(), | ||
responseType, | ||
callback | ||
); | ||
} | ||
|
||
public LoginPushedAuthorizationRequest( | ||
OAuth2Service oAuth2Service, | ||
ProfileHint profileHint, | ||
String clientId, | ||
String responseType, | ||
Callback callback | ||
) { | ||
this.oAuth2Service = oAuth2Service; | ||
this.profileHint = profileHint; | ||
this.clientId = clientId; | ||
this.responseType = responseType.toLowerCase(Locale.US); | ||
this.callback = callback; | ||
this.moshi = new Moshi.Builder().build(); | ||
} | ||
|
||
public void execute() { | ||
if (profileHint == null) { | ||
callback.onSuccess(""); | ||
return; | ||
} | ||
JsonAdapter<ProfileHint> profileHintJsonAdapter = moshi.adapter(ProfileHint.class); | ||
String profileHintString = new String( | ||
Base64.getEncoder().encode( | ||
profileHintJsonAdapter.toJson(profileHint).getBytes(UTF_8) | ||
) | ||
); | ||
oAuth2Service | ||
.loginParRequest(clientId, responseType, profileHintString) | ||
.enqueue(new retrofit2.Callback<LoginPARResponse>() { | ||
@Override | ||
public void onResponse(Call<LoginPARResponse> call, Response<LoginPARResponse> response) { | ||
callback.onSuccess(response.body().requestUri); | ||
} | ||
|
||
@Override | ||
public void onFailure(Call<LoginPARResponse> call, Throwable t) { | ||
callback.onError(new LoginPARRequestException(t)); | ||
} | ||
}); | ||
} | ||
|
||
static OAuth2Service createOAuthService(String baseUrl) { | ||
return new Retrofit.Builder() | ||
.baseUrl(baseUrl) | ||
.addConverterFactory(MoshiConverterFactory.create()) | ||
.build() | ||
.create(OAuth2Service.class); | ||
} | ||
|
||
public static interface Callback { | ||
void onSuccess(String requestUri); | ||
|
||
void onError(LoginPARRequestException e); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be in internal, it's in the public facing API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call. will raise a separate pr for it