Refresh token for Google Storage Client2019 Community Moderator ElectionGlass quick start for .NET and refresh tokenCreating Customer in Quickbooks Online from C#OAuth Bearer Access Token sliding expirationNot able to get new refresh token from azure AD with grant type refresh_token called with old refresh tokenOAuth 2.0 How to invalidate granted auth tokens using password grantEbay REST API - application token for listing products and updating inventoryWebAPI Non-interactive authenticating to Azure AD using username & passwordC# set access_type = offline for AuthorizeAsync?Why caching access token is consider bad in oauth2?How to deal with access tokens on apache beam
If Invisibility ends because the original caster casts a non-concentration spell, does Invisibility also end on other targets of the original casting?
Single word request: Harming the benefactor
Do Bugbears' arms literally get longer when it's their turn?
When were linguistics departments first established
Want to switch to tankless, but can I use my existing wiring?
Welcoming 2019 Pi day: How to draw the letter π?
What does おとこえしや mean?
Plywood subfloor won't screw down in a trailer home
What has been your most complicated TikZ drawing?
Do I need to leave some extra space available on the disk which my database log files reside, for log backup operations to successfully occur?
"However" used in a conditional clause?
What is the difference between "shut" and "close"?
Should we release the security issues we found in our product as CVE or we can just update those on weekly release notes?
Why do Australian milk farmers need to protest supermarkets' milk price?
Are there situations where a child is permitted to refer to their parent by their first name?
Excess Zinc in garden soil
Should QA ask requirements to developers?
Is a lawful good "antagonist" effective?
Making a sword in the stone, in a medieval world without magic
Counter-example to the existence of left Bousfield localization of combinatorial model category
validation vs test vs training accuracy, which one to compare for claiming overfit?
Decoding assembly instructions in a Game Boy disassembler
Good allowance savings plan?
What exactly is the purpose of connection links straped between the rocket and the launch pad
Refresh token for Google Storage Client
2019 Community Moderator ElectionGlass quick start for .NET and refresh tokenCreating Customer in Quickbooks Online from C#OAuth Bearer Access Token sliding expirationNot able to get new refresh token from azure AD with grant type refresh_token called with old refresh tokenOAuth 2.0 How to invalidate granted auth tokens using password grantEbay REST API - application token for listing products and updating inventoryWebAPI Non-interactive authenticating to Azure AD using username & passwordC# set access_type = offline for AuthorizeAsync?Why caching access token is consider bad in oauth2?How to deal with access tokens on apache beam
I must be stupid I think. Using OAuth
.
Have the following piece of code
// Authenticate with Google
using (MemoryStream stream =
new MemoryStream(GetSecrets()))
string credPath = "token.json";
this.userCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
Works fine and sets this.userCredential
as expected
Now I want to create a StorageClient
But StorageClient
cannot be created directly from UserCredential
.
The only way I can see is to create from the AccessToken
GoogleCredential googleCredential = GoogleCredential.FromAccessToken(this.userCredential.Token.AccessToken);
return StorageClient.Create(googleCredential);
Problem is this token expires after an hour.
However, in C# I cannot for the life of me find a way to pass in the refresh token (which I have in the UserCredential) and have it refresh itself as needed
It seems possible in Java
though, using the .Builder
Does anyone know if this is possible ?
c# .net google-cloud-platform
New contributor
add a comment |
I must be stupid I think. Using OAuth
.
Have the following piece of code
// Authenticate with Google
using (MemoryStream stream =
new MemoryStream(GetSecrets()))
string credPath = "token.json";
this.userCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
Works fine and sets this.userCredential
as expected
Now I want to create a StorageClient
But StorageClient
cannot be created directly from UserCredential
.
The only way I can see is to create from the AccessToken
GoogleCredential googleCredential = GoogleCredential.FromAccessToken(this.userCredential.Token.AccessToken);
return StorageClient.Create(googleCredential);
Problem is this token expires after an hour.
However, in C# I cannot for the life of me find a way to pass in the refresh token (which I have in the UserCredential) and have it refresh itself as needed
It seems possible in Java
though, using the .Builder
Does anyone know if this is possible ?
c# .net google-cloud-platform
New contributor
add a comment |
I must be stupid I think. Using OAuth
.
Have the following piece of code
// Authenticate with Google
using (MemoryStream stream =
new MemoryStream(GetSecrets()))
string credPath = "token.json";
this.userCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
Works fine and sets this.userCredential
as expected
Now I want to create a StorageClient
But StorageClient
cannot be created directly from UserCredential
.
The only way I can see is to create from the AccessToken
GoogleCredential googleCredential = GoogleCredential.FromAccessToken(this.userCredential.Token.AccessToken);
return StorageClient.Create(googleCredential);
Problem is this token expires after an hour.
However, in C# I cannot for the life of me find a way to pass in the refresh token (which I have in the UserCredential) and have it refresh itself as needed
It seems possible in Java
though, using the .Builder
Does anyone know if this is possible ?
c# .net google-cloud-platform
New contributor
I must be stupid I think. Using OAuth
.
Have the following piece of code
// Authenticate with Google
using (MemoryStream stream =
new MemoryStream(GetSecrets()))
string credPath = "token.json";
this.userCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
Works fine and sets this.userCredential
as expected
Now I want to create a StorageClient
But StorageClient
cannot be created directly from UserCredential
.
The only way I can see is to create from the AccessToken
GoogleCredential googleCredential = GoogleCredential.FromAccessToken(this.userCredential.Token.AccessToken);
return StorageClient.Create(googleCredential);
Problem is this token expires after an hour.
However, in C# I cannot for the life of me find a way to pass in the refresh token (which I have in the UserCredential) and have it refresh itself as needed
It seems possible in Java
though, using the .Builder
Does anyone know if this is possible ?
c# .net google-cloud-platform
c# .net google-cloud-platform
New contributor
New contributor
edited Mar 7 at 11:01
Sagar P. Ghagare
5292721
5292721
New contributor
asked Mar 7 at 9:19
Nick AmbroseNick Ambrose
132
132
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The simplest way of achieving this is to create the StorageService
yourself, and then pass that to the StorageClientImpl
constructor:
var service = new StorageService(new BaseClientService.Initializer
HttpClientInitializer = userCredential,
ApplicationName = StorageClientImpl.ApplicationName,
);
StorageClient client = new StorageClientImpl(service);
We might consider adding an overload of Create
that takes an IConfigurableHttpClientInitializer
instead of a GoogleCredential
, in the future.
If this works, thank you so much!!!! Seems wrong to mess with an Impl -- hope that won't break going forward. But its way better than continually creating new clients with manually refreshed AccessTokens !
– Nick Ambrose
Mar 7 at 10:23
@NickAmbrose: No, the "Impl" class is part of the public API - we won't be breaking it. The separation between StorageClient and StorageClientImpl is primarily so that can write test doubles of StorageClient.
– Jon Skeet
Mar 7 at 10:39
3
Jon -- I cannot thank you enough, this solved my problem perfectly! I really appreciate you taking the time to respond.
– Nick Ambrose
Mar 7 at 14:33
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Nick Ambrose is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55040095%2frefresh-token-for-google-storage-client%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The simplest way of achieving this is to create the StorageService
yourself, and then pass that to the StorageClientImpl
constructor:
var service = new StorageService(new BaseClientService.Initializer
HttpClientInitializer = userCredential,
ApplicationName = StorageClientImpl.ApplicationName,
);
StorageClient client = new StorageClientImpl(service);
We might consider adding an overload of Create
that takes an IConfigurableHttpClientInitializer
instead of a GoogleCredential
, in the future.
If this works, thank you so much!!!! Seems wrong to mess with an Impl -- hope that won't break going forward. But its way better than continually creating new clients with manually refreshed AccessTokens !
– Nick Ambrose
Mar 7 at 10:23
@NickAmbrose: No, the "Impl" class is part of the public API - we won't be breaking it. The separation between StorageClient and StorageClientImpl is primarily so that can write test doubles of StorageClient.
– Jon Skeet
Mar 7 at 10:39
3
Jon -- I cannot thank you enough, this solved my problem perfectly! I really appreciate you taking the time to respond.
– Nick Ambrose
Mar 7 at 14:33
add a comment |
The simplest way of achieving this is to create the StorageService
yourself, and then pass that to the StorageClientImpl
constructor:
var service = new StorageService(new BaseClientService.Initializer
HttpClientInitializer = userCredential,
ApplicationName = StorageClientImpl.ApplicationName,
);
StorageClient client = new StorageClientImpl(service);
We might consider adding an overload of Create
that takes an IConfigurableHttpClientInitializer
instead of a GoogleCredential
, in the future.
If this works, thank you so much!!!! Seems wrong to mess with an Impl -- hope that won't break going forward. But its way better than continually creating new clients with manually refreshed AccessTokens !
– Nick Ambrose
Mar 7 at 10:23
@NickAmbrose: No, the "Impl" class is part of the public API - we won't be breaking it. The separation between StorageClient and StorageClientImpl is primarily so that can write test doubles of StorageClient.
– Jon Skeet
Mar 7 at 10:39
3
Jon -- I cannot thank you enough, this solved my problem perfectly! I really appreciate you taking the time to respond.
– Nick Ambrose
Mar 7 at 14:33
add a comment |
The simplest way of achieving this is to create the StorageService
yourself, and then pass that to the StorageClientImpl
constructor:
var service = new StorageService(new BaseClientService.Initializer
HttpClientInitializer = userCredential,
ApplicationName = StorageClientImpl.ApplicationName,
);
StorageClient client = new StorageClientImpl(service);
We might consider adding an overload of Create
that takes an IConfigurableHttpClientInitializer
instead of a GoogleCredential
, in the future.
The simplest way of achieving this is to create the StorageService
yourself, and then pass that to the StorageClientImpl
constructor:
var service = new StorageService(new BaseClientService.Initializer
HttpClientInitializer = userCredential,
ApplicationName = StorageClientImpl.ApplicationName,
);
StorageClient client = new StorageClientImpl(service);
We might consider adding an overload of Create
that takes an IConfigurableHttpClientInitializer
instead of a GoogleCredential
, in the future.
answered Mar 7 at 9:23
Jon SkeetJon Skeet
1092k69279688457
1092k69279688457
If this works, thank you so much!!!! Seems wrong to mess with an Impl -- hope that won't break going forward. But its way better than continually creating new clients with manually refreshed AccessTokens !
– Nick Ambrose
Mar 7 at 10:23
@NickAmbrose: No, the "Impl" class is part of the public API - we won't be breaking it. The separation between StorageClient and StorageClientImpl is primarily so that can write test doubles of StorageClient.
– Jon Skeet
Mar 7 at 10:39
3
Jon -- I cannot thank you enough, this solved my problem perfectly! I really appreciate you taking the time to respond.
– Nick Ambrose
Mar 7 at 14:33
add a comment |
If this works, thank you so much!!!! Seems wrong to mess with an Impl -- hope that won't break going forward. But its way better than continually creating new clients with manually refreshed AccessTokens !
– Nick Ambrose
Mar 7 at 10:23
@NickAmbrose: No, the "Impl" class is part of the public API - we won't be breaking it. The separation between StorageClient and StorageClientImpl is primarily so that can write test doubles of StorageClient.
– Jon Skeet
Mar 7 at 10:39
3
Jon -- I cannot thank you enough, this solved my problem perfectly! I really appreciate you taking the time to respond.
– Nick Ambrose
Mar 7 at 14:33
If this works, thank you so much!!!! Seems wrong to mess with an Impl -- hope that won't break going forward. But its way better than continually creating new clients with manually refreshed AccessTokens !
– Nick Ambrose
Mar 7 at 10:23
If this works, thank you so much!!!! Seems wrong to mess with an Impl -- hope that won't break going forward. But its way better than continually creating new clients with manually refreshed AccessTokens !
– Nick Ambrose
Mar 7 at 10:23
@NickAmbrose: No, the "Impl" class is part of the public API - we won't be breaking it. The separation between StorageClient and StorageClientImpl is primarily so that can write test doubles of StorageClient.
– Jon Skeet
Mar 7 at 10:39
@NickAmbrose: No, the "Impl" class is part of the public API - we won't be breaking it. The separation between StorageClient and StorageClientImpl is primarily so that can write test doubles of StorageClient.
– Jon Skeet
Mar 7 at 10:39
3
3
Jon -- I cannot thank you enough, this solved my problem perfectly! I really appreciate you taking the time to respond.
– Nick Ambrose
Mar 7 at 14:33
Jon -- I cannot thank you enough, this solved my problem perfectly! I really appreciate you taking the time to respond.
– Nick Ambrose
Mar 7 at 14:33
add a comment |
Nick Ambrose is a new contributor. Be nice, and check out our Code of Conduct.
Nick Ambrose is a new contributor. Be nice, and check out our Code of Conduct.
Nick Ambrose is a new contributor. Be nice, and check out our Code of Conduct.
Nick Ambrose is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55040095%2frefresh-token-for-google-storage-client%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown