public async Task <JObject> GetUserProfileAsync() { Credencial credencial = await CredencialService.FromSessionAsync(Request.Cookies, Response.Cookies); if (credencial == null) { return(null); } // the API SDK UserProfileApi userApi = new UserProfileApi(); userApi.Configuration.AccessToken = credencial.TokenInternal; // get the user profile dynamic userProfile = await userApi.GetUserProfileAsync(); // prepare a response with name & picture dynamic response = new JObject(); response.name = string.Format("{0} {1}", userProfile.firstName, userProfile.lastName); response.picture = userProfile.profileImages.sizeX40; response.token = credencial.TokenInternal; return(response); }
public IActionResult Singout() { // finish the session CredencialService.Signout(base.Response.Cookies); return(Redirect("/")); }
public async Task <AccessToken> GetPublicTokenAsync() { Credencial credencial = await CredencialService.FromSessionAsync(Request.Cookies, Response.Cookies); if (credencial == null) { base.Response.StatusCode = (int)HttpStatusCode.Unauthorized; return(new AccessToken()); } // return the public (viewables:read) access token return(new AccessToken() { access_token = credencial.TokenPublic, expires_in = (int)credencial.ExpiresAt.Subtract(DateTime.Now).TotalSeconds }); //Credentials credentials = await Credentials.FromSessionAsync(Request.Cookies, Response.Cookies); //if (credentials == null) //{ // base.Response.StatusCode = (int)HttpStatusCode.Unauthorized; // return new AccessToken(); //} //// return the public (viewables:read) access token //return new AccessToken() //{ // access_token = credentials.TokenPublic, // expires_in = (int)credentials.ExpiresAt.Subtract(DateTime.Now).TotalSeconds //}; }
[Route("api/forge/callback/oauth")] // see Web.Config FORGE_CALLBACK_URL variable public async Task <IActionResult> OAuthCallbackAsync(string code) { // create credentials form the oAuth CODE Credencial credencial = await CredencialService.CreateFromCodeAsync(code, Response.Cookies); return(Redirect("http://localhost:4200")); }
public string GetOAuthURL() { // prepare the sign in URL Scope[] scopes = { Scope.DataRead }; ThreeLeggedApi _threeLeggedApi = new ThreeLeggedApi(); string oauthUrl = _threeLeggedApi.Authorize( CredencialService.GetAppSetting("FORGE_CLIENT_ID"), oAuthConstants.CODE, CredencialService.GetAppSetting("FORGE_CALLBACK_URL"), new Scope[] { Scope.DataRead, Scope.DataCreate, Scope.DataWrite, Scope.ViewablesRead }); return(oauthUrl); }
[Route("api/forge/clientid")] // see Web.Config FORGE_CALLBACK_URL variable public dynamic GetClientID() { return(new { id = CredencialService.GetAppSetting("FORGE_CLIENT_ID") }); }