How to implement OAuth in google classroom

你离开我真会死。 提交于 2020-01-07 09:09:19

问题


Presently i am working on google classroom API to integrate classroom into my .NET product.I am using below method for authenticating user.My problem is when i execute this code it asking authentication for first time but when i execute this code next time it directly log in as previous log in credentials.When i try this after many days and many browsers also directly log in as first authenticated user.But for every fresh time execution of code i want it ask for authentication of user rather than directly log in as previous user credentials.How to achieve this...? I am new to this OAuth and API's.Your valuable answer will help my team a lot.

please any one help me on this...

private ClassroomService getservice()
        {
            using (var stream =
              new FileStream(Server.MapPath("client_secret1.json"), FileMode.Open, FileAccess.Read))
            {

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                      CancellationToken.None).Result;
            }
            var service = new ClassroomService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = ApplicationName,
            });
            return service;
        }

回答1:


Even if you don't pass in a data store object, the library by default will store the user's credentials in C:\Users\%USERNAME%\AppData\Roaming\Google.Apis.Auth\. If you don't want to store the auth information at all, and instead have the user authorize the application on each run, you'll need to pass in a custom data store object that doesn't actually store the credentials:

class NullDataStore : IDataStore
{
    public Task StoreAsync<T>(string key, T value) 
    {
        return Task.Delay(0);
    }

    public Task DeleteAsync<T>(string key)
    {
        return Task.Delay(0);
    }

    public Task<T> GetAsync<T>(string key)
    {
        return Task.FromResult(default(T));
    }

    public Task ClearAsync()
    {
        return Task.Delay(0);
    }

}

Then pass an instance of this class into the AuthorizeAsync() method:

credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    GoogleClientSecrets.Load(stream).Secrets,
    Scopes,
    "user",
    CancellationToken.None,
    new NullDataStore()).Result;


来源:https://stackoverflow.com/questions/32070888/how-to-implement-oauth-in-google-classroom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!