Created
September 14, 2020 23:04
-
-
Save mlescaille/62cf53d4c5d8b63e3ee4a8698866cd74 to your computer and use it in GitHub Desktop.
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
package com.tutorial.googleeoauth.domain | |
import com.google.api.client.auth.oauth2.StoredCredential | |
import groovy.transform.CompileStatic | |
import javax.persistence.Entity | |
import javax.validation.constraints.NotNull | |
import java.time.LocalDateTime | |
/** | |
* Represents credential details for Google's APIs. | |
*/ | |
@Entity | |
@CompileStatic | |
class GoogleCredentialDetails extends BaseEntity { | |
@NotNull | |
String uuid | |
Long adServerUserProfileId | |
@NotNull | |
String oauthClientId | |
@NotNull | |
String oauthClientSecret | |
String accountName | |
String accessToken | |
String refreshToken | |
Long expirationTimeMilliseconds | |
public void apply(StoredCredential credential) { | |
this.accessToken = credential.getAccessToken() | |
this.expirationTimeMilliseconds = credential.getExpirationTimeMilliseconds() | |
this.refreshToken = credential.getRefreshToken() | |
this.updatedAt = LocalDateTime.now() | |
} | |
public StoredCredential toStoredCredential() { | |
StoredCredential credential = new StoredCredential() | |
credential.setAccessToken(this.accessToken) | |
credential.setRefreshToken(this.refreshToken) | |
credential.setExpirationTimeMilliseconds(this.expirationTimeMilliseconds) | |
return credential | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment