public bool setEntry(Ticket ticket, string Realm, string UserID, Permission_Claim claim) { AccessToken at = (AccessToken)ticket; AccessTokenEntry ate = (AccessTokenEntry)claim; if (at == null && claim == null) { return(false); } Dictionary[at] = new Dictionary <string, Dictionary <string, AccessTokenEntry> >(); Dictionary[at][Realm] = new Dictionary <string, AccessTokenEntry>(); Dictionary[at][Realm][UserID] = ate; return(true); }
/// <inheritdoc /> public async Task CompleteAuthorization(string code, IResponseCookies cookies, CancellationToken cancellationToken) { if (code == null) { throw new ArgumentNullException(nameof(code)); } if (cookies == null) { throw new ArgumentNullException(nameof(cookies)); } logger.LogTrace("CompleteAuthorization for with code: {0}", code); var otr = new OauthTokenRequest(gitHubConfiguration.OauthClientID, gitHubConfiguration.OauthSecret, code); var result = await gitHubClient.Oauth.CreateAccessToken(otr).ConfigureAwait(false); if (result.AccessToken == null || !result.Scope.Contains(RequiredScope)) { //user is f*****g with us, don't even bother return; } var expiry = DateTime.Now.AddDays(AccessTokenCookieExpriationDays); var newEntry = new AccessTokenEntry() { Id = Guid.NewGuid(), AccessToken = result.AccessToken, Expiry = expiry }; cookies.Append(CookieName, newEntry.Id.ToString(), new CookieOptions { SameSite = SameSiteMode.Strict, Secure = true, Expires = expiry }); await databaseContext.AccessTokenEntries.AddAsync(newEntry, cancellationToken).ConfigureAwait(false); await databaseContext.Save(cancellationToken).ConfigureAwait(false); }