1/*
2* Copyright 2018 - Present Okta, Inc.
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8*      http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15 */
16
17// AUTO-GENERATED!  DO NOT EDIT FILE DIRECTLY
18
19package okta
20
21import (
22	"fmt"
23	"time"
24)
25
26type SessionResource resource
27
28type Session struct {
29	Links                    interface{}                    `json:"_links,omitempty"`
30	Amr                      []*SessionAuthenticationMethod `json:"amr,omitempty"`
31	CreatedAt                *time.Time                     `json:"createdAt,omitempty"`
32	ExpiresAt                *time.Time                     `json:"expiresAt,omitempty"`
33	Id                       string                         `json:"id,omitempty"`
34	Idp                      *SessionIdentityProvider       `json:"idp,omitempty"`
35	LastFactorVerification   *time.Time                     `json:"lastFactorVerification,omitempty"`
36	LastPasswordVerification *time.Time                     `json:"lastPasswordVerification,omitempty"`
37	Login                    string                         `json:"login,omitempty"`
38	Status                   string                         `json:"status,omitempty"`
39	UserId                   string                         `json:"userId,omitempty"`
40}
41
42func (m *SessionResource) GetSession(sessionId string) (*Session, *Response, error) {
43	url := fmt.Sprintf("/api/v1/sessions/%v", sessionId)
44	req, err := m.client.requestExecutor.NewRequest("GET", url, nil)
45	if err != nil {
46		return nil, nil, err
47	}
48
49	var session *Session
50	resp, err := m.client.requestExecutor.Do(req, &session)
51	if err != nil {
52		return nil, resp, err
53	}
54	return session, resp, nil
55}
56func (m *SessionResource) EndSession(sessionId string) (*Response, error) {
57	url := fmt.Sprintf("/api/v1/sessions/%v", sessionId)
58	req, err := m.client.requestExecutor.NewRequest("DELETE", url, nil)
59	if err != nil {
60		return nil, err
61	}
62
63	resp, err := m.client.requestExecutor.Do(req, nil)
64	if err != nil {
65		return resp, err
66	}
67	return resp, nil
68}
69func (m *SessionResource) CreateSession(body CreateSessionRequest) (*Session, *Response, error) {
70	url := fmt.Sprintf("/api/v1/sessions")
71	req, err := m.client.requestExecutor.NewRequest("POST", url, body)
72	if err != nil {
73		return nil, nil, err
74	}
75
76	var session *Session
77	resp, err := m.client.requestExecutor.Do(req, &session)
78	if err != nil {
79		return nil, resp, err
80	}
81	return session, resp, nil
82}
83func (m *SessionResource) RefreshSession(sessionId string) (*Session, *Response, error) {
84	url := fmt.Sprintf("/api/v1/sessions/%v/lifecycle/refresh", sessionId)
85	req, err := m.client.requestExecutor.NewRequest("POST", url, nil)
86	if err != nil {
87		return nil, nil, err
88	}
89
90	var session *Session
91	resp, err := m.client.requestExecutor.Do(req, &session)
92	if err != nil {
93		return nil, resp, err
94	}
95	return session, resp, nil
96}
97