Skip to content

Instantly share code, notes, and snippets.

@mlescaille
Created September 14, 2020 23:04
Show Gist options
  • Save mlescaille/62cf53d4c5d8b63e3ee4a8698866cd74 to your computer and use it in GitHub Desktop.
Save mlescaille/62cf53d4c5d8b63e3ee4a8698866cd74 to your computer and use it in GitHub Desktop.
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