forked from scribejava/scribejava
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add email field to VKOAuth2AccessToken (thanks to https://github.com/…
- Loading branch information
Showing
6 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
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
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
31 changes: 31 additions & 0 deletions
31
scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKJsonTokenExtractor.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,31 @@ | ||
package com.github.scribejava.apis.vk; | ||
|
||
import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* additionally parses email | ||
*/ | ||
public class VKJsonTokenExtractor extends OAuth2AccessTokenJsonExtractor { | ||
|
||
private static final Pattern EMAIL_REGEX_PATTERN = Pattern.compile("\"email\"\\s*:\\s*\"(\\S*?)\""); | ||
|
||
protected VKJsonTokenExtractor() { | ||
} | ||
|
||
private static class InstanceHolder { | ||
|
||
private static final VKJsonTokenExtractor INSTANCE = new VKJsonTokenExtractor(); | ||
} | ||
|
||
public static VKJsonTokenExtractor instance() { | ||
return InstanceHolder.INSTANCE; | ||
} | ||
|
||
@Override | ||
protected VKOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, | ||
String refreshToken, String scope, String response) { | ||
return new VKOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, | ||
extractParameter(response, EMAIL_REGEX_PATTERN, false), response); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
scribejava-apis/src/main/java/com/github/scribejava/apis/vk/VKOAuth2AccessToken.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,50 @@ | ||
package com.github.scribejava.apis.vk; | ||
|
||
import com.github.scribejava.core.model.OAuth2AccessToken; | ||
import java.util.Objects; | ||
|
||
public class VKOAuth2AccessToken extends OAuth2AccessToken { | ||
|
||
private static final long serialVersionUID = -3539517142527580499L; | ||
|
||
private final String email; | ||
|
||
public VKOAuth2AccessToken(String accessToken, String email, String rawResponse) { | ||
this(accessToken, null, null, null, null, email, rawResponse); | ||
} | ||
|
||
public VKOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, | ||
String scope, String email, String rawResponse) { | ||
super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse); | ||
this.email = email; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hash = super.hashCode(); | ||
hash = 37 * hash + Objects.hashCode(email); | ||
return hash; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
if (!super.equals(obj)) { | ||
return false; | ||
} | ||
|
||
return Objects.equals(email, ((VKOAuth2AccessToken) obj).getEmail()); | ||
} | ||
} |
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
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