예제 #1
0
        /// <summary>
        /// Converts Guest Issuer token result to Teams token result.
        /// </summary>
        /// <param name="source">Source result.</param>
        /// <param name="refreshedAt"><see cref="DateTime"/> when the token refreshed.</param>
        /// <param name="guestUserId">Guest user id.</param>
        /// <param name="displayName">Guest user display name.</param>
        /// <returns><see cref="TeamsResult{TTeamsObject}"/> to get result.</returns>
        private static TeamsResult <GuestUserInfo> convert(TeamsResult <GuestTokenInternalInfo> source, DateTime refreshedAt, string guestUserId, string displayName)
        {
            var result = new TeamsResult <GuestUserInfo>();

            source.CopyInfoTo(result);


            var guestUserInfo = new GuestUserInfo();

            var data = source.Data;

            if (result.IsSuccessStatus)
            {
                guestUserInfo.UserId      = guestUserId;
                guestUserInfo.DisplayName = displayName;

                guestUserInfo.RefreshedAt = refreshedAt;

                guestUserInfo.AccessToken = data.Token;

                if (data.ExpiresIn.HasValue)
                {
                    guestUserInfo.AccessTokenExpiresIn = TimeSpan.FromSeconds(data.ExpiresIn.Value);
                    guestUserInfo.AccessTokenExpiresAt = refreshedAt + guestUserInfo.AccessTokenExpiresIn;
                }
            }

            if (data.HasExtensionData)
            {
                guestUserInfo.JsonExtensionData = data.JsonExtensionData;
            }

            guestUserInfo.HasValues = data.HasValues;

            result.Data = guestUserInfo;

            return(result);
        }
예제 #2
0
 /// <summary>
 /// Refreshed the Guest user token.
 /// Make sure your local clock is accurate or synced with NTP. Otherwise, it may fail to create guest user because of expiration of issuer token.
 /// </summary>
 /// <param name="guestUserInfo"><see cref="GuestUserInfo"/> which the token will be refreshed.</param>
 /// <param name="cancellationToken"><see cref="CancellationToken"/> to be used for cancellation.</param>
 /// <returns><see cref="TeamsResult{TTeamsObject}"/> to get result.</returns>
 public Task <TeamsResult <GuestUserInfo> > RefreshGuestUserTokenAsync(GuestUserInfo guestUserInfo, CancellationToken?cancellationToken = null)
 {
     return(CreateGuestUserAsync(guestUserInfo.UserId, guestUserInfo.DisplayName, cancellationToken));
 }