Esempio n. 1
0
 public RefreshTokenAuthenticationProvider(string clientId, string clientSecret, string redirectUri, OAuthSession session, Action <string> storeSession)
 {
     this.Session      = session;
     this.ClientID     = clientId;
     this.ClientSecret = ClientSecret;
     this.RedirectUri  = redirectUri;
     this.storeSession = storeSession;
 }
Esempio n. 2
0
 public OneDriveClient(string clientId, string clientSecret, string redirectUri, OAuthSession session, Action <string> storeSession)
 {
     this.Session      = session;
     this.ClientID     = clientId;
     this.ClientSecret = clientSecret;
     this.RedirectUri  = redirectUri;
     this.storeSession = storeSession;
 }
Esempio n. 3
0
        public async Task AuthenticateRequestAsync(HttpRequestMessage request)
        {
            if (!Session.IsValid())
            {
                Session = await AuthenticationHelper.RequestAccessToken(ClientID, ClientSecret, RedirectUri, Session.RefreshToken);

                storeSession?.Invoke(JsonConvert.SerializeObject(Session));
            }

            request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", Session.AccessToken);
        }
Esempio n. 4
0
        public async Task <bool> Authenticate(Dictionary <string, string> data)
        {
            OAuthSession session = await AuthenticationHelper.RequestRefreshToken(ClientID, ClientSecret, callbackUrl, data["code"]);

            if (session == null || !session.IsValid())
            {
                throw new ArgumentNullException("Failed to retreive refresh_token");
            }

            storeSession?.Invoke(JsonConvert.SerializeObject(session));

            return(true);
        }
Esempio n. 5
0
        public OneDriveClient GetAuthenticatedClient(string storedSession)
        {
            OAuthSession session = JsonConvert.DeserializeObject <OAuthSession>(storedSession);

            if (string.IsNullOrWhiteSpace(session.RefreshToken))
            {
                throw new ArgumentNullException(nameof(session.RefreshToken));
            }

            OneDriveClient client = new OneDriveClient(ClientID, ClientSecret, callbackUrl, session, this.storeSession);

            return(client);
        }
Esempio n. 6
0
        public IOneDriveClient GetAuthenticatedClient(string storedSession)
        {
            OAuthSession session = JsonConvert.DeserializeObject <OAuthSession>(storedSession);

            if (string.IsNullOrWhiteSpace(session.RefreshToken))
            {
                throw new ArgumentNullException(nameof(session.RefreshToken));
            }

            RefreshTokenAuthenticationProvider authenticationProvider = new RefreshTokenAuthenticationProvider(ClientID, ClientSecret, callbackUrl, session, this.storeSession);
            IOneDriveClient client = new OneDriveClient("https://api.onedrive.com/v1.0", authenticationProvider);

            return(client);
        }